angular.module('starter.productCtrl', [])
    .controller('ProductxtzgDetailCtrl', function ($scope, $rootScope, $stateParams, $ionicScrollDelegate, $faModal, $location, $faAPI, $faPopup, $faUser, $faMAP, $state, product, $faLoading, $faIOSBridge, $ionicNavBarDelegate, $timeout, $faWechat, $faPlatform, $ionicPopup, $yukuvideo, $authorize, $filter, $faUtil) {

        var issm = $stateParams.issm;
        $scope.proid = $stateParams.id;

        //分享信息
        $scope.share = $stateParams.share;
        $scope.sharePhone = $stateParams.sharePhone;
        //是否协议价
        $scope.isagreement = false;
        //筛选图标状态
        $scope.isFilterSle = false;
        var sfavideo = product.result.sfaVideo;


        if (sfavideo != undefined) {
            if (sfavideo.isEncryption == 0) {
                VIDEO_PWD = sfavideo.encryptionPassword;
            } else {
                VIDEO_PWD = '';
            }

            $yukuvideo.play(sfavideo.videoId, sfavideo.id);
        }
        $scope.item = (function (item) {
            if (item.expectSaleAmount != 0) {
                item.process = ((item.allSubscriptionAmount * 100 / item.expectSaleAmount).toFixed(2) > 100) ? 100 : (item.allSubscriptionAmount * 100 / item.expectSaleAmount).toFixed(2);
            } else {
                item.process = 0;
            }
            for (var i = 0; i < item.profitAndRebateList.length; i++) {
                if (item.profitAndRebateList[i].pIsAgreement == 1) {
                    //是否协议价
                    $scope.isagreement = true;
                }
            }
            return item;
        })(product.result);
        //产品详情由富文本拆分的字段
        try {
            $scope.summary = JSON.parse(product.result.summary);
        }
        catch (err) {
        }
        //7-15私募基金法更改--wap4.1.3--del-code
        //if (!$faUser.info.isLogin && !$scope.share) {
        //    $rootScope.modal.login();
        //}
        //// 产品详情
        function getData() {

            $faAPI.product.detail({
                code: $stateParams.id
            }).then(function (json) {
                console.log(json)
                $scope.item = (function (item) {
                    if (item.expectSaleAmount != 0) {
                        item.process = ((item.allSubscriptionAmount * 100 / item.expectSaleAmount).toFixed(2) > 100) ? 100 : (item.allSubscriptionAmount * 100 / item.expectSaleAmount).toFixed(2);
                    } else {
                        item.process = 0;
                    }
                    for (var i = 0; i < item.profitAndRebateList.length; i++) {
                        if (item.profitAndRebateList[i].pIsAgreement == 1) {
                            //是否协议价
                            $scope.isagreement = true;
                        }
                    }
                    return item;
                })(json.result);

                getBiddingQuery();
            });

        }

        getData();

        function examinelogin() {
            $scope.user.info.isLogin = true;
        }

        $scope.gologin = function () {
            $rootScope.modal.login(examinelogin);
        };
        $faModal('xtzg_modal', 'views/modals/xtzgdetail_modal.html', $scope);
        $faModal('pevc_modal', 'views/modals/pevcdetail_modal.html', $scope);

        //产品详情
        $scope.openOrder = function (type) {
            if (type) {
                $scope.modal.xtzg_modal();
            } else {
                $scope.modal.pevc_modal();
            }
        };
        function getBiddingQuery() {
            //获取含竞价的返佣信息
            $faAPI.product.biddingQuery({
                pId: $scope.item.productId
            }).then(function (res) {
                $scope.res = res;
            });
        }

        ////复制简版功能提示
        //if($faPlatform.androidAPP || $faPlatform.IOSAPP){
        //    var hintv = document.getElementById('hintcopy');
        //    if(!window.localStorage.ishintCopy){
        //        hintv.style.display = 'block';
        //    }
        //    $scope.hidehintCopy = function(){
        //        hintv.style.display = 'none';
        //        window.localStorage.ishintCopy = true;
        //    };
        //}


        //要做全局的登陆认证状态监听更新数据
        $scope.$watch('userRole', function (newValue) {
            if (newValue) {
                getData();
                getBiddingQuery();
                if (sfavideo != undefined) {
                    if (sfavideo.isEncryption == 0) {
                        VIDEO_PWD = sfavideo.encryptionPassword;
                    } else {
                        VIDEO_PWD = '';
                    }

                    $yukuvideo.play(sfavideo.videoId, sfavideo.id);
                }
            }
        });


        $scope.params = $location.search();
        if ($scope.params.name) {
            $scope.uName = decodeURI($scope.params.name);
        }

        if ($scope.params.share && window.location.href.indexOf('view') < 0 && window.location.href.indexOf('shop') < 0) {
            $timeout(function () {
                $ionicNavBarDelegate.showBar(false);
            }, 0);
        }
        //竞价收单
        $scope.goBid = function (id) {
            if ($scope.xtzg_modal) {
                $scope.xtzg_modal.hide();
            }
            if ($scope.isagreement) {
                $ionicPopup.alert({
                    title: '协议价产品无法竞价',
                    okText: '好的',
                    okType: 'button-assertive'
                });
                return
            }
            if ($faUser.info.isLogin) {
                if (!$rootScope.userRole) {
                    $ionicPopup.confirm({
                        title: '你还未上传名片或在审核中,上传并审核通过后才能竞价收单',
                        cancelText: '取消',
                        okText: '去上传',
                        cancelType: '',
                        okType: 'button-assertive'
                    }).then(function (res) {

                        if (!res) {

                        }
                        if (res) {
                            $state.go('app.myself.certification')
                        }
                    });
                } else {
                    $faAPI.product.queryOldBiddingReceipt({
                        pId: id
                    }).then(function (res) {
                        if (res.flagOldBidding) {
                            $ionicPopup.confirm({
                                title: '你已提交过竞价,是否继续？',
                                cancelText: '取消',
                                okText: '继续竞价',
                                cancelType: '',
                                okType: 'button-assertive'
                            }).then(function (res) {
                                if (res) {
                                    $state.go('product.bidding', {pid: id})
                                }
                            });
                        } else {
                            $state.go('product.bidding', {pid: id})
                        }
                    });
                }


            } else {
                $rootScope.modal.login();
            }


        };
        //立即预约
        $scope.goOrder = function (id) {
            //点击预约需要关闭详情弹层
            if ($scope.xtzg_modal) {
                $scope.xtzg_modal.hide();
            }
            if ($scope.pevc_modal) {
                $scope.pevc_modal.hide();
            }
            $faUser.info.isLogin ? $state.go('product.xtzgOrder', {pid: id}) : $rootScope.modal.login();
        };

        //(店铺立刻预约)
        $scope.goClientOrder = function (id, type, name, phone) {
            //点击预约需要关闭详情弹层
            if ($scope.xtzg_modal) {
                $scope.xtzg_modal.hide();
            }
            if ($scope.pevc_modal) {
                $scope.pevc_modal.hide();
            }
            $state.go('product.clientOrder', {productId: id, productType: type, productName: name, sphone: phone});
        };
        $scope.goCertification = function ($event) {
            $event.stopPropagation();
            $faUser.info.isLogin ? $state.go('app.myself.certification') : $rootScope.modal.login();
        };
        //放弃承销
        $scope.giveup = function (id) {
            if ($scope.xtzg_modal) {
                $scope.xtzg_modal.hide();
            }

            var giveupPopup = $ionicPopup.confirm({
                title: '是否放弃承销权?',
                buttons: [
                    {text: '取消'},
                    {
                        text: '<b>确定</b>',
                        type: 'button-default',
                        onTap: function (e) {
                            e.preventDefault();
                            $faAPI.product.dropBiddingReceipt({
                                biddingReceiptId: id
                            }).then(function (res) {
                                giveupPopup.close();
                                $scope.res.biddingReceiptUserInfo.currentBiddingIsLogin = false;
                            });
                        }
                    }]
            });
        };
        //是否活动主推
        $scope.isM2bProduct = function (product) {
            var flag = false, product = product || {};
            if (product && product.activitiesMollionsWealthList && product.activitiesMollionsWealthList.length) {
                angular.forEach(product.activitiesMollionsWealthList, function (o) {
                    if (o.activitiesProductType == "04") {
                        flag = true;
                    }
                });
            }
            return flag;
        };

        //分享后微信中添加后台统计
        function shopStatis() {
            //信托：110201
            //资管：110202
            //pevc：110203
            //阳光私募：110204
            var reqData = {
                type: '110201',
                host: $location.host(),
                path: $location.path(),
                param: $stateParams.id,
                source: 'WAP',
                shopId: $scope.sharePhone

            };
            $faAPI.shops.statis({
                type: 'statisitics',
                data: reqData
            }).then(function (json) {
            });
        }

        //扫码后微信中添加后台统计
        function shopSmStatis(){
            var reqData = {
                type: '110505',
                host: $location.host(),
                path: $location.path(),
                param: $location.search(),
                source: 'WAP',
                shopId: $scope.sharePhone,
                userId: $scope.sharePhone
            };
            $faAPI.shops.statis({
                type: 'statisitics',
                data: reqData
            }).then(function (json) {
            });
        }

        //根据分享的手机号码查询信息
        if ($stateParams.sharePhone) {

            $faAPI.user.getUserForLonginName({
                loginName: $stateParams.sharePhone,
                productId: product.result.productCode,
                productType: product.result.productType

            }).then(function (json) {
               /* console.log(json)*/
                $scope.sharePhoneInfo = json.dto;
                $scope.tuijianReson = json.shopperProductDto.tuijianReson;

                if(!issm) {
                    if (($faPlatform.weChat)) {
                        //是否微信授权
                        if (!json.wechatId) {
                            $authorize.maAuth(shopStatis);
                        } else {
                            shopStatis()
                        }
                    }
                } else {
                    shopSmStatis();
                }
                console.log(json)
                $scope.shopperUserInfoDto = json.shopperUserInfoDto;
                $scope.productState = json.shopperProductDto.productState;

            });
        } else {
            //产品详情埋点
            function shopProStatis() {
                //信托：110201
                //资管：110202
                //pevc：110203
                //阳光私募：110204
                var reqData = {
                    type: '110508',
                    host: $location.host(),
                    path: $location.path(),
                    param: $stateParams.id,
                    source: 'WAP',
                    shopId: $faUser.info.mobile

                };
                $faAPI.shops.statis({
                    type: 'statisitics',
                    data: reqData
                }).then(function (json) {
                });
            }
            shopProStatis();
        }

        // 收藏

        // 判断是否收藏

        if ($faUser.info.isLogin) {
            $faAPI.product.starList({
                pId: $scope.item.productId

            }).then(function (json) {

                if (json.list.length > 0) {
                    $scope.item.starId = json.list[0].id
                }

            });
        }
        // 加入收藏
        $scope.star = function () {
            if ($faUser.info.isLogin) {
                if (!$scope.item.starId) {
                    $faAPI.product.star({
                        pId: $scope.item.productId,
                        likeType: '1'
                    }).then(function (json) {
                        $scope.item.starId = json.id;
                    });

                } else {
                    $faAPI.product.cancelStar({
                        id: $scope.item.starId,
                        pId: $scope.item.productId
                    }).then(function () {
                        delete $scope.item.starId;
                    });
                }
            } else {
                $rootScope.modal.login();
            }
        };

        // 留言列表
        $faModal('comment', 'views/product/comment.html', $scope, {
            initialize: function () {
                var self = this;

                self.pager = {
                    hasNaxtPage: true,
                    pageSize: 10,
                    nextPage: 1
                };

                $scope.comments = [];
            },
            loadMoreItems: function () {

                var self = this;

                self.data = {
                    _pId: $scope.item.productId,
                    pageNo: self.pager.nextPage,
                    pageSize: self.pager.pageSize
                };

                $faAPI.productComment.list(self.data).then(function (json) {
                    $scope.comments = $scope.comments.concat(json.list);
                    self.pager = json.pager;
                    $scope.$broadcast('scroll.infiniteScrollComplete');
                });
            },
            up: function (index, id) {

                var data = {
                    pCommentsId: id
                };

                if ($faUser.info.isLogin) {

                    $faAPI.productComment.up(data).then(function () {
                        $scope.comments[index].upCount += 1;
                    });

                } else {
                    $rootScope.modal.login();
                }

            }
        });

        // 写留言
        $faModal('writeComment', 'views/product/writeComment.html', $scope, {
            initialize: function () {

                var self = this;

                self.data = {
                    pId: $scope.item.productId
                };


            },
            done: function () {

                var self = this;

                if (!self.data.pCommentsContent) {
                    $faPopup.alert({
                        title: '请输入评论内容'
                    })
                } else {

                    if ($faUser.info.isLogin) {

                        $faAPI.productComment.add(self.data).then(function (json) {

                            var data = {
                                _pId: $scope.item.productId,
                                _pt: 'wap'
                            }


                            $scope.comments.unshift(json.list[0]);

                            self.hide();

                        });

                    } else {
                        $rootScope.modal.login();
                    }


                }

            }
        });

        // 下载附件
        $faModal('download', 'views/product/download.html', $scope, {
            done: function (id) {

                var self = this;

                var data = {
                    id: id,
                    pId: $scope.item.productId
                };

                if ($faUser.info.isLogin) {

                    $faAPI.product.download(data).then(function () {
                        self.hide();
                    });

                } else {
                    $rootScope.modal.login();
                }

            }
        });

        // 产品预约
        $faModal('order', 'views/product/order.html', $scope, {
            initialize: function () {
                var self = this;
                self.data = {};
                self.data.pid = $scope.item.productId;
            },
            done: function () {
                var self = this;

                if (!self.data.name) {

                    $faPopup.alert({
                        title: '请输入您的姓名'
                    });

                } else if (!$faMAP.regular.name.test(self.data.name)) {

                    $faPopup.alert({
                        title: '姓名格式输入有误'
                    });

                } else if (!self.data.mobile) {

                    $faPopup.alert({
                        title: '请输入您的手机号码'
                    });

                } else if (!$faMAP.regular.mobile.test(self.data.mobile)) {

                    $faPopup.alert({
                        title: '手机格式输入有误'
                    });

                } else if (!self.data.amount) {

                    $faPopup.alert({
                        title: '请输入您的预约金额'
                    });

                } else if (!$faMAP.regular.integer.test(self.data.amount)) {

                    $faPopup.alert({
                        title: '预约金额输入格式有误'
                    });

                } else {

                    $faAPI.order.applyPre(self.data).then(function (json) {
                        $faPopup.alert({
                            title: '预约成功，请等待专业顾问回复'
                        });
                        $state.go('app.deal');
                        self.hide();
                    });

                }

            }
        });
        $scope.openWriteComm = function () {
            if (!$faUser.info.isLogin) {
                $rootScope.modal.login();
            } else {
                $scope.modal.writeComment();
            }
        };
        $scope.orderOpen = function () {
            if (!$faUser.info.isLogin) {
                $rootScope.modal.login();
            } else {
                $scope.modal.order();
            }
        };


        //分享产品详情
        $scope.proshare = function () {
            //分享结束执行
            window.shareCallBack = function () {
                var param = {
                    productType: $scope.item.productType,
                    productId: $scope.item.productCode
                };
                $faAPI.shops.productAddToShopsShare(param).then(function (json) {
                });
            }
            //微信简版版本
            //未登录的情况下也可以分享产品
            var data;
            if ($faUser.info.isLogin) {
                //$rootScope.modal.login();
                //5.信托、资管：投资领域、付息方式、大小配比
                data = {
                    title: $scope.item.productShortName,
                    desc: '投资领域：' + $scope.item.investDesc + '；付息方式：' + $scope.item.paymentInterestTypeDesc + '；大小配比：' + $scope.item.pSizeRatioExplain,
                    link: reqUrl + '/#/product/xtzgdetail/' + $scope.item.productCode + '?share=true&sharePhone=' + $faUser.info.mobile,
                    imgUrl: citeImgUrl + $scope.item.pImageUrl
                };

            } else {
                data = {
                    title: $scope.item.productShortName,
                    desc: '投资领域：' + $scope.item.investDesc + '；付息方式：' + $scope.item.paymentInterestTypeDesc + '；大小配比：' + $scope.item.pSizeRatioExplain,
                    link: reqUrl + '/#/product/xtzgdetail/' + $scope.item.productCode + '?share=true',
                    imgUrl: citeImgUrl + $scope.item.pImageUrl
                };
            }


            if ($faPlatform.androidAPP) {
                document.addEventListener("deviceready", OnDeviceReady, false);
                function OnDeviceReady() {
                    cordova.exec(null, null, "MyPlugin", "toShare", [data.title, data.desc, data.link, data.imgUrl]);
                }

                window.shareCallBack();
            } else {
                productShare(data.title, data.desc, data.link, data.imgUrl);
            }

        };
        //ng-model绑定input输入获取值要定义成对象
        //http://jimhoskins.com/2012/12/14/nested-scopes-in-angularjs.html
        $scope.mailData = {};

        $faModal('send_mail', 'views/modals/sendMail.html', $scope, {
            initialize: function () {
                //console.log($scope.modal.send_mail());
            },
            done: function () {
                var self = this;
                $faAPI.product.sendMail({
                    pId: $scope.item.productId,
                    pType: $scope.item.productType,
                    emailAddress: $scope.mailData.sendMailUrl
                }).then(function () {
                    $ionicPopup.alert({
                        title: '发送邮件成功'
                    });
                    $rootScope.snedMailHistory.push($scope.mailData.sendMailUrl);
                    $rootScope.snedMailHistory = unique2($rootScope.snedMailHistory.reverse());
                    $scope.mailData.sendMailUrl = null;
                    self.hide();
                });

            }
        });

        //发送邮件--使用全局函数让native调用
        window.showSendMail = function () {
            $scope.modal.send_mail();
        };

        //清空发送邮件历史记录
        $scope.delsnedEmailHis = function () {
            $rootScope.snedMailHistory = [];
        };


        //复制简版
        $faModal('copy_brief', 'views/modals/copyBrief.html', $scope, {
            initialize: function () {
                $scope.copyType = 'xtzg';
                //是否包销
                if (product.result.flagBaoxiao) {
                    $scope.copyisbaoxiao = '***SFA独家包销***';
                }
                //资金用途
                $scope.copyzjyt = $scope.summary.zjyt ? $scope.summary.zjyt.replace(/<[^>]+>/g, "") : '-';
                //风险控制
                $scope.copyfxkz = $scope.summary.fxkz ? $scope.summary.fxkz.replace(/<[^>]+>/g, "") : '-';
                //产品优势
                $scope.copycpys = $scope.summary.cpys ? $scope.summary.cpys.replace(/<[^>]+>/g, "") : '-';
                //募集账号
                $scope.copymjzh = $scope.summary.mjzh ? $scope.summary.mjzh.replace(/<[^>]+>/g, "") : '-';
                if ($faUser.info.isLogin) {

                    $scope.copyuserinfo = '';
                    if ($faUser.info.realName) {
                        $scope.copyuserinfo = '联系人:' + $faUser.info.realName;
                    }
                    $scope.copyuserinfo = $scope.copyuserinfo + ' 联系电话:' + $faUser.info.mobile;
                }

            },
            done: function () {
                var data = document.getElementById('copyData').value;

                if ($faPlatform.androidAPP) {
                    document.addEventListener("deviceready", OnDeviceReady, false);
                    function OnDeviceReady() {
                        cordova.exec(null, null, "MyPlugin", "copy", [data]);
                    }
                } else {
                    copy(data);
                }

            }
        });
        window.showCopyBrief = function () {
            $scope.modal.copy_brief();
        };
        function h5Copy(data, name) {
            var clipboard = new Clipboard('.' + name, {
                text: function () {
                    return data;
                }
            });
            var myPopup = $ionicPopup.show({
                title: '复制成功',
                scope: $scope,
                buttons: []
            });
            $timeout(function () {
                myPopup.close(); //由于某种原因3秒后关闭弹出
            }, 2000);
        }

        function androidCopy(data) {

            document.addEventListener("deviceready", OnDeviceReady, false);
            function OnDeviceReady() {
                cordova.exec(null, null, "MyPlugin", "copy", [data]);
            }

        }

        //复制模块
        $scope.copyInfo = function (name) {

            if (name == 'jcxx') {
                var data = '【产品全称】：' + $scope.item.productName + '\n' +
                    '【募集规模】：' + $filter('abbrMoney')($scope.item.allIssuingScale) + '\n' +
                    '【投资领域】：' + $scope.item.investDesc + '\n' +
                    '【付息方式】：' + $scope.item.paymentInterestTypeDesc + '\n' +
                    '【大小配比】：' + $scope.item.pSizeRatioExplain + '\n' +
                    '【发行机构】：' + $scope.item.investOwner + '\n' +
                    '【投资期限】：' + $scope.item.dueTime + '个月' + '\n' +
                    '【发行时间】：' + $scope.item.saleDateStart.split(' ')[0];
                if (ISWEB) {
                    h5Copy(data, 'jcxx');
                } else {
                    if ($faPlatform.androidAPP) {
                        androidCopy(data);
                    } else {
                        copy(data);
                    }

                }


            }
            if (name == 'cpys') {
                var data = $scope.summary.cpys.replace(/<[a-z]+>/g, '')
                    .replace(/<[^>]+>/g, '\n').replace(/\n+/g, '\n');
                if (ISWEB) {
                    h5Copy(data, 'cpys');
                } else {
                    if ($faPlatform.androidAPP) {
                        androidCopy(data);
                    } else {
                        copy(data);
                    }

                }

            }
            if (name == 'mjzh') {
                var data = $scope.summary.mjzh.replace(/<[a-z]+>/g, '')
                    .replace(/<[^>]+>/g, '\n').replace(/\n+/g, '\n');
                if (ISWEB) {
                    h5Copy(data, 'mjzh');
                } else {
                    if ($faPlatform.androidAPP) {
                        androidCopy(data);
                    } else {
                        copy(data);
                    }

                }

            }
            if (name == 'fxkz') {

                var data = $scope.summary.fxkz.replace(/<[a-z]+>/g, '')
                    .replace(/<[^>]+>/g, '\n').replace(/\n+/g, '\n');

                if (ISWEB) {
                    h5Copy(data, 'fxkz');
                } else {
                    if ($faPlatform.androidAPP) {
                        androidCopy(data);
                    } else {
                        copy(data);
                    }
                }

            }


        };


        //微信分享
        if ($faUser.info.isLogin) {
            $faWechat.api.onMenuShareTimeline({
                title: $scope.item.productShortName + '－金策师', // 分享标题
                link: $location.protocol() + '://' + $location.host() + '/#/product/xtzgdetail/' + $scope.item.productCode + '?share=true&sharePhone=' + $faUser.info.mobile, // 分享链接
                imgUrl: $location.protocol() + '://' + $location.host() + $scope.item.pImageUrl, // 分享图标
                success: function () {
                    // 用户确认分享后执行的回调函数
                    var param = {
                        productType: $scope.item.productType,
                        productId: $scope.item.productCode
                    };
                    $faAPI.shops.productAddToShopsShare(param).then(function (json) {
                    });
                },
                cancel: function () {
                    // 用户取消分享后执行的回调函数
                }
            });
            $faWechat.api.onMenuShareAppMessage({
                title: $scope.item.productShortName + '－金策师', // 分享标题
                desc: '投资领域：' + $scope.item.investDesc + '；付息方式：' + $scope.item.paymentInterestTypeDesc + '；大小配比：' + $scope.item.pSizeRatioExplain, // 分享描述
                link: $location.protocol() + '://' + $location.host() + '/#/product/xtzgdetail/' + $scope.item.productCode + '?share=true&sharePhone=' + $faUser.info.mobile, // 分享链接
                imgUrl: $location.protocol() + '://' + $location.host() + $scope.item.pImageUrl, // 分享图标
                type: 'link', // 分享类型,music、video或link，不填默认为link
                dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
                success: function () {
                    // 用户确认分享后执行的回调函数
                    var param = {
                        productType: $scope.item.productType,
                        productId: $scope.item.productCode
                    };
                    $faAPI.shops.productAddToShopsShare(param).then(function (json) {
                    });
                },
                cancel: function () {
                    // 用户取消分享后执行的回调函数
                }
            })
        }
        else if ($scope.share) {
            //2016/12/08新增需求,APP分享出来后，没有登录，带分享人的信息
            $faWechat.api.onMenuShareTimeline({
                title: $scope.item.productShortName + '－金策师', // 分享标题
                link: $location.protocol() + '://' + $location.host() + '/#/product/xtzgdetail/' + $scope.item.productCode + '?share=true&sharePhone=' + $scope.sharePhone,
                imgUrl: $location.protocol() + '://' + $location.host() + $scope.item.pImageUrl, // 分享图标
                success: function () {
                    // 用户确认分享后执行的回调函数
                    var param = {
                        productType: $scope.item.productType,
                        productId: $scope.item.productCode
                    };
                    $faAPI.shops.productAddToShopsShare(param).then(function (json) {
                    });
                },
                cancel: function () {
                    // 用户取消分享后执行的回调函数
                }
            });
            $faWechat.api.onMenuShareAppMessage({
                title: $scope.item.productShortName + '－金策师', // 分享标题
                desc: '投资领域：' + $scope.item.investDesc + '；付息方式：' + $scope.item.paymentInterestTypeDesc + '；大小配比：' + $scope.item.pSizeRatioExplain, // 分享描述
                link: $location.protocol() + '://' + $location.host() + '/#/product/xtzgdetail/' + $scope.item.productCode + '?share=true&sharePhone=' + $scope.sharePhone, // 分享链接
                imgUrl: $location.protocol() + '://' + $location.host() + $scope.item.pImageUrl, // 分享图标
                type: 'link', // 分享类型,music、video或link，不填默认为link
                dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
                success: function () {
                    // 用户确认分享后执行的回调函数
                    var param = {
                        productType: $scope.item.productType,
                        productId: $scope.item.productCode
                    };
                    $faAPI.shops.productAddToShopsShare(param).then(function (json) {
                    });
                },
                cancel: function () {
                    // 用户取消分享后执行的回调函数
                }
            })
        } else {

            $faWechat.api.onMenuShareTimeline({
                title: $scope.item.productShortName + '－金策师', // 分享标题
                link: $location.protocol() + '://' + $location.host() + '/#/product/xtzgdetail/' + $scope.item.productCode,
                imgUrl: $location.protocol() + '://' + $location.host() + $scope.item.pImageUrl, // 分享图标
                success: function () {
                    // 用户确认分享后执行的回调函数
                    var param = {
                        productType: $scope.item.productType,
                        productId: $scope.item.productCode
                    };
                    $faAPI.shops.productAddToShopsShare(param).then(function (json) {
                    });
                },
                cancel: function () {
                    // 用户取消分享后执行的回调函数
                }
            });
            $faWechat.api.onMenuShareAppMessage({
                title: $scope.item.productShortName + '－金策师', // 分享标题
                desc: '投资领域：' + $scope.item.investDesc + '；付息方式：' + $scope.item.paymentInterestTypeDesc + '；大小配比：' + $scope.item.pSizeRatioExplain, // 分享描述
                link: $location.protocol() + '://' + $location.host() + '/#/product/xtzgdetail/' + $scope.item.productCode, // 分享链接
                imgUrl: $location.protocol() + '://' + $location.host() + $scope.item.pImageUrl, // 分享图标
                type: 'link', // 分享类型,music、video或link，不填默认为link
                dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
                success: function () {
                    // 用户确认分享后执行的回调函数
                    var param = {
                        productType: $scope.item.productType,
                        productId: $scope.item.productCode
                    };
                    $faAPI.shops.productAddToShopsShare(param).then(function (json) {
                    });
                },
                cancel: function () {
                    // 用户取消分享后执行的回调函数
                }
            })
        }

        //产品推荐

        $faAPI.product.getRecommendProductForProductInfo({
            pId: product.result.productId
        }).then(function (json) {
            // console.log(json);
            $scope.recommendProduct = json.list || [];
        });


        //加入对比
        $scope.addContrast = function ($event, code, name) {

            $event.stopPropagation();

            $rootScope.contrastData[name] = code;

            //console.log($rootScope.contrastData);

            $faUtil.localStorage('contrastData', $rootScope.contrastData);
            $state.go('contrastIndex');

        }


    })
    .controller('xtzgOrderCtrl', function ($scope, $faMAP, $faAPI, $faPopup, $stateParams,$faUser) {
        $faUser.update();
        console.log($faUser)
        var data = {};
        $scope.data = data;
        $scope.isSuccess = false;

        $scope.data.pid = $stateParams.pid;
        var type = $stateParams.type;
        $scope.orderName = $stateParams.name;
        //console.log($scope.orderName);
        console.log($scope.data)
        console.log(type)
        $scope.comit = function () {
            if (!$scope.data.name) {

                $faPopup.alert({
                    title: '请输入您的姓名'
                });

            } else if (!$faMAP.regular.name.test($scope.data.name)) {

                $faPopup.alert({
                    title: '姓名格式输入有误'
                });

            } else if (!$scope.data.amount && !$scope.orderName) {

                $faPopup.alert({
                    title: '请输入您的预约金额'
                });

            } else if (!$faMAP.regular.integer.test($scope.data.amount) && !$scope.orderName) {

                $faPopup.alert({
                    title: '预约金额输入格式有误'
                });

            } else {
                //type为私募预约
                //orderName为海外保险预约
                if (type) {
                    $faAPI.order.applyPreTmpSM({
                        oAmount: $scope.data.amount,
                        oClientName: $scope.data.name,
                        productId: $scope.data.pid,
                        oRemark: $scope.data.remark
                    }).then(function (json) {
                        $scope.isSuccess = true;
                        console.log(json)
                    });
                } else if ($scope.orderName) {
                    $faAPI.order.hwbxApplyPre({
                        fpHybxProjectId: $scope.data.pid,
                        fpHybxProject: $scope.orderName,
                        fpHybxRemark: $scope.data.remark
                    }).then(function (json) {
                        $scope.isSuccess = true;
                        console.log(json)
                    });
                } else {
                    $faAPI.order.applyPre($scope.data).then(function (json) {
                        $scope.isSuccess = true;
                        console.log(json)
                    });
                }


            }
        }

    })
    .controller('contrastIndexCtrl',function($scope,$faUtil,$rootScope,$ionicPopup,$timeout,$faModal,$faAPI){
        $scope.contrastData = $faUtil.localStorage('contrastData');
        var conSleData = {};
        $scope.isRedact = false;
        $scope.addselData = function(name,code){

            if(conSleData[name]){
                delete  conSleData[name];
            }else {
                conSleData[name] = code;

            }


            console.log(conSleData);
        };
        $scope.contrastRedact = function(){
            $scope.isRedact = true;
            $scope.select_one = false;
            conSleData = {};
        };

        $faModal('contrast', 'views/product/contrast/contrast_modal.html', $scope, {
            initialize: function() {

                var self = this;
                var code_ = '';

                for(var item in conSleData){
                    console.log(conSleData[item]);
                    code_ += conSleData[item]+','
                }
                $faAPI.product.compare({
                    code:code_
                }).then(function(json){
                    console.log(json);
                    $scope.duibiData = json.list || [];
                });

            },
            done: function() {

                var self = this;

                self.hide();

            }
        });
        $scope.beginContrast = function(){
            var arr = Object.keys(conSleData);
            var myPopup;
            if(arr.length<2){
                myPopup  = $ionicPopup.show({
                    title: '请至少选择两个产品对比',
                    scope: $scope,
                    buttons: []
                });
                $timeout(function() {
                    myPopup.close(); //由于某种原因3秒后关闭弹出
                }, 2000);
            }else if(arr.length>3){
                myPopup = $ionicPopup.show({
                    title: '最多选择三个产品对比',
                    scope: $scope,
                    buttons: []
                });
                $timeout(function() {
                    myPopup.close(); //由于某种原因3秒后关闭弹出
                }, 2000);
            }else {
                $scope.modal.contrast();
            }


        };
        $scope.selectAll = function(){
            if($scope.select_one){
                $scope.select_one = false;
                conSleData = {};
                console.log('取消全选');
                console.log(conSleData);
            }else {
                $scope.select_one = true;

                conSleData = angular.copy($scope.contrastData);
                console.log('全选');
                console.log(conSleData);
            }

        };
        $scope.contrast_del = function(){
            $scope.isRedact = false;
            for(var item in conSleData){
                delete  conSleData[item];
                delete  $scope.contrastData[item];
                delete  $rootScope.contrastData[item];

            }
            $faUtil.localStorage('contrastData',$rootScope.contrastData)

        };

    })
    .controller('ProductPevcDetailCtrl',function($scope,$rootScope,$stateParams,$ionicScrollDelegate,$faModal, $location, $faAPI, $faPopup, $faUser,$faMAP, $state, $faLoading, $faIOSBridge, $ionicNavBarDelegate,$timeout,$faWechat,$faPlatform,$ionicPopup,$filter,$yukuvideo,$authorize){
        //登录成功后需要更新数据，由于xtzg--pevc是不同的接口，所以新建controller
        var issm = $stateParams.issm;
        $scope.share = $stateParams.share;
        $scope.sharePhone = $stateParams.sharePhone;
        console.log( $scope.sharePhone)
        $scope.isagreement = false;
        $scope.isFilterSle = false;
        //7-15私募基金法更改--wap4.1.3--del-code
        //if (!$faUser.info.isLogin && !$scope.share) {
        //    $rootScope.modal.login();
        //}

        var proid = $stateParams.id;
        $scope.proid = proid;

        function getPevcData(){
            ////获取pevc 产品详情
            $faAPI.product.pevcDetail({
                code: $stateParams.id
            }).then(function(json){
                console.log(json)
                $scope.item = (function(item) {
                    if (item.expectSaleAmount != 0) {
                        item.process = ((item.allSubscriptionAmount * 100 / item.expectSaleAmount).toFixed(2) > 100) ? 100 : (item.allSubscriptionAmount * 100 / item.expectSaleAmount).toFixed(2);
                    } else {
                        item.process = 0;
                    }
                    for(var i=0;i<item.profitAndRebateList.length;i++){
                        if(item.profitAndRebateList[i].pIsAgreement == 1){
                            //是否协议价
                            $scope.isagreement = true;
                        }
                    }
                    return item;
                })(json.result);
                //产品详情由富文本拆分的字段
                try {
                    $scope.summary = JSON.parse(json.result.summary);
                    $scope.pevcDetailData = json;

                }
                catch(err){

                }
                //优酷视频
                var sfavideo = json.result.sfaVideo;

                if(sfavideo != undefined){
                    if(sfavideo.isEncryption == 0){
                        VIDEO_PWD = sfavideo.encryptionPassword;
                    }else {
                        VIDEO_PWD = '';
                    }
                    $yukuvideo.play(sfavideo.videoId,sfavideo.id);
                }
                getUserForLonginName();
                weichatShare();
                isStar();
                getRecommendProductForProductInfo();


            });
        }
        getPevcData();

        function examinelogin(){
            $scope.user.info.isLogin = true;
        }
        $scope.gologin = function(){
            $rootScope.modal.login(examinelogin);
        };
        $faModal('xtzg_modal','views/modals/xtzgdetail_modal.html',$scope);
        $faModal('pevc_modal','views/modals/pevcdetail_modal.html',$scope);

        //产品详情
        $scope.openOrder = function(type){
            if(type){
                $scope.modal.xtzg_modal();
            }else {
                $scope.modal.pevc_modal();
            }
        };

        //要做全局的登陆认证状态监听更新数据
        $scope.$watch('userRole',function(newValue){
            if(newValue){
                getPevcData();
            }
        });

        function h5Copy(data,name){
            var clipboard = new Clipboard('.'+name, {
                text: function() {
                    return data;
                }
            });

            var myPopup = $ionicPopup.show({
                title: '复制成功',
                scope: $scope,
                buttons: []
            });
            $timeout(function() {
                myPopup.close(); //由于某种原因3秒后关闭弹出
            }, 2000);
        }
        function androidCopy(data){

            document.addEventListener("deviceready",OnDeviceReady, false);
            function OnDeviceReady()
            {
                cordova.exec(null, null, "MyPlugin", "copy", [data]);
            }

        }
        //复制模块
        $scope.copyInfo =function(name){

            if(name == 'jcxx'){
                var peSubscriptionFee = ($scope.item.peSubscriptionFee || $scope.item.peSubscriptionFee === 0)?$scope.item.peSubscriptionFee+'%':'-';
                var peManagementExpense = ($scope.item.peManagementExpense || $scope.item.peManagementExpense === 0)?$scope.item.peManagementExpense+'%':'-';
                console.log(peSubscriptionFee);
                var data  = '【产品全称】：'+$scope.item.productName+'\n'+
                    '【募集规模】：'+$filter('abbrMoney')($scope.item.allIssuingScale)+'\n'+
                    '【基金类型】：'+$scope.item.peFundShape+'\n'+
                    '【组织形式】：'+$filter('zuzhixingshi')($scope.item.peOrganizeShape)+'\n'+
                    '【发行地区】：'+$filter('faxingdiqu')($scope.item.publicArea)+'\n'+
                    '【管理机构】：'+$scope.item.peManageOrg+'\n'+
                    '【产品期限】：'+$scope.item.dueTime+'个月'+'\n'+
                    '【认购费】：'+peSubscriptionFee+'\n'+
                    '【管理费】：'+peManagementExpense;
                if(ISWEB){
                    h5Copy(data,'jcxx');
                }else {
                    if($faPlatform.androidAPP){
                        androidCopy(data);
                    }else {
                        copy(data);
                    }

                }

            }
            if(name == 'cpys'){
                var data = $scope.summary.xmld.replace(/<[a-z]+>/g, '')
                    .replace(/<[^>]+>/g, '\n').replace(/\n+/g, '\n');
                if(ISWEB){
                    h5Copy(data,'cpys');
                }else {
                    if($faPlatform.androidAPP){
                        androidCopy(data);
                    }else {
                        copy(data);
                    }

                }


            }
            if(name == 'mjzh'){
                var data = $scope.summary.mjzh.replace(/<[a-z]+>/g, '')
                    .replace(/<[^>]+>/g, '\n').replace(/\n+/g, '\n');
                if(ISWEB){
                    h5Copy(data,'mjzh');
                }else {
                    if($faPlatform.androidAPP){
                        androidCopy(data);
                    }else {
                        copy(data);
                    }

                }

            }
            if(name == 'fxkz'){
                var data  = $scope.summary.fxkz.replace(/<[a-z]+>/g, '')
                    .replace(/<[^>]+>/g, '\n').replace(/\n+/g, '\n');
                console.log(data);
                if(ISWEB){
                    h5Copy(data,'fxkz');
                }else {
                    if($faPlatform.androidAPP){
                        androidCopy(data);
                    }else {
                        copy(data);
                    }

                }

            }


        };

        $scope.params = $location.search();
        if($scope.params.name){
            $scope.uName =decodeURI($scope.params.name);
        }


        if ($scope.params.share && window.location.href.indexOf('view')<0 && window.location.href.indexOf('shop')<0) {
            $timeout(function() {
                $ionicNavBarDelegate.showBar(false);
            }, 0);
        }

        //立即预约
        $scope.goOrder = function(id){
            //点击预约需要关闭详情弹层
            if($scope.xtzg_modal){
                $scope.xtzg_modal.hide();
            }
            if($scope.pevc_modal){
                $scope.pevc_modal.hide();
            }
            $faUser.info.isLogin ? $state.go('product.xtzgOrder',{pid:id}) : $rootScope.modal.login();
        };
        //立即预约
        //(店铺立刻预约)
        $scope.goClientOrder = function(id,type,name,phone){
            //点击预约需要关闭详情弹层
            if($scope.xtzg_modal){
                $scope.xtzg_modal.hide();
            }
            if($scope.pevc_modal){
                $scope.pevc_modal.hide();
            }
            $state.go('product.clientOrder',{productId:id,productType:type,productName:name,sphone:phone});
        };
        $scope.goCertification = function($event){
            $event.stopPropagation();
            $faUser.info.isLogin ? $state.go('app.myself.certification') : $rootScope.modal.login();
        };


        // 下载附件
        $faModal('download', 'views/product/download.html', $scope, {
            done: function(id) {

                var self = this;

                var data = {
                    id: id,
                    pId: $scope.item.productId
                };

                if ($faUser.info.isLogin) {

                    $faAPI.product.download(data).then(function() {
                        self.hide();
                    });

                } else {
                    $rootScope.modal.login();
                }

            }
        });

        // 收藏

        // 判断是否收藏
        function isStar(){
            if ($faUser.info.isLogin) {
                $faAPI.product.starList({
                    pId: $scope.item.productId

                }).then(function(json) {

                    if (json.list.length > 0) {
                        $scope.item.starId = json.list[0].id
                    }

                });
            }
            // 加入收藏
            $scope.star = function() {
                if ($faUser.info.isLogin) {
                    if (!$scope.item.starId) {
                        $faAPI.product.star({
                            pId: $scope.item.productId,
                            likeType:'1'
                        }).then(function(json) {
                            $scope.item.starId = json.id;
                        });

                    } else {
                        $faAPI.product.cancelStar({
                            id: $scope.item.starId,
                            pId: $scope.item.productId
                        }).then(function() {
                            delete $scope.item.starId;
                        });
                    }
                } else {
                    $rootScope.modal.login();
                }
            };
        }

        //产品推荐
        function getRecommendProductForProductInfo(){
            $faAPI.product.getRecommendProductForProductInfo({
                pId:$scope.item.productId
            }).then(function(json){
                console.log(json);
                $scope.recommendProduct = json.list || [];
            });
        }

        $scope.openWriteComm = function(){
            if (!$faUser.info.isLogin) {
                $rootScope.modal.login();
            } else {
                $scope.modal.writeComment();
            }
        };
        $scope.orderOpen = function() {
            if (!$faUser.info.isLogin) {
                $rootScope.modal.login();
            } else {
                $scope.modal.order();
            }
        };

        //分享产品详情
        $scope.proshare = function(){
            //分享结束执行
            window.shareCallBack = function() {
                var param = {
                    productType: $scope.item.productType,
                    productId: $scope.item.productCode
                };
                $faAPI.shops.productAddToShopsShare(param).then(function(json) {});
            };
            var data;
            $scope.item.peOrganizeShape= $filter('zuzhixingshi')($scope.item.peOrganizeShape);
            if ($faUser.info.isLogin) {
                //7.股权基金： 发行机构、组织形式、基金类型
                data = {
                    title:$scope.item.productShortName,
                    desc:'发行机构：'+$scope.item.investOwner+'；组织形式：'+$scope.item.peOrganizeShape+'；基金类型：'+$scope.item.peFundShape,
                    link:reqUrl + '/#/product/pevc/' + $scope.item.productCode+'?share=true&sharePhone='+$faUser.info.mobile,
                    imgUrl:citeImgUrl+$scope.item.pImageUrl
                };

            }else {
                //7.股权基金： 发行机构、组织形式、基金类型
                data = {
                    title:$scope.item.productShortName,
                    desc:'发行机构：'+$scope.item.investOwner+'；组织形式：'+$scope.item.peOrganizeShape+'；基金类型：'+$scope.item.peFundShape,
                    link:reqUrl + '/#/product/pevc/' + $scope.item.productCode+'?share=true',
                    imgUrl:citeImgUrl+$scope.item.pImageUrl
                };
            }




            if($faPlatform.androidAPP){
                document.addEventListener("deviceready",OnDeviceReady, false);
                function OnDeviceReady()
                {
                    cordova.exec(null, null, "MyPlugin", "toShare", [data.title,data.desc,data.link,data.imgUrl]);
                }
                window.shareCallBack();
            }else{
                productShare(data.title,data.desc,data.link,data.imgUrl);
            }

        };

        function weichatShare(){
            //微信分享
            if($faUser.info.isLogin){
                $faWechat.api.onMenuShareTimeline({
                    title: $scope.item.productShortName + '－金策师', // 分享标题
                    link: $location.protocol() + '://' + $location.host() + '/#/product/pevc/' + $scope.item.productCode+'?share=true&sharePhone='+$faUser.info.mobile, // 分享链接
                    imgUrl: $location.protocol() + '://' + $location.host()+$scope.item.pImageUrl, // 分享图标
                    success: function() {
                        // 用户确认分享后执行的回调函数
                        var param = {
                            productType: $scope.item.productType,
                            productId: $scope.item.productCode
                        };
                        $faAPI.shops.productAddToShopsShare(param).then(function(json) {});
                    },
                    cancel: function() {
                        // 用户取消分享后执行的回调函数
                    }
                });
                $faWechat.api.onMenuShareAppMessage({
                    title: $scope.item.productShortName + '－金策师', // 分享标题
                    desc: '发行机构：'+$scope.item.investOwner+'；组织形式：'+$scope.item.peOrganizeShape+'；基金类型：'+$scope.item.peFundShape, // 分享描述
                    link: $location.protocol() + '://' + $location.host() + '/#/product/pevc/' + $scope.item.productCode+'?share=true&sharePhone='+$faUser.info.mobile, // 分享链接
                    imgUrl: $location.protocol() + '://' + $location.host()+$scope.item.pImageUrl, // 分享图标
                    type: 'link', // 分享类型,music、video或link，不填默认为link
                    dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
                    success: function() {
                        // 用户确认分享后执行的回调函数
                        var param = {
                            productType: $scope.item.productType,
                            productId: $scope.item.productCode
                        };
                        $faAPI.shops.productAddToShopsShare(param).then(function(json) {});
                    },
                    cancel: function() {
                        // 用户取消分享后执行的回调函数
                    }
                })
            }
            else if($scope.share){
                //2016/12/08新增需求,APP分享出来后，没有登录，带分享人的信息
                $faWechat.api.onMenuShareTimeline({
                    title: $scope.item.productShortName + '－金策师', // 分享标题
                    link: $location.protocol() + '://' + $location.host() + '/#/product/xtzgdetail/' + $scope.item.productCode+'?share=true&sharePhone='+$scope.sharePhone,
                    imgUrl: $location.protocol() + '://' + $location.host()+$scope.item.pImageUrl, // 分享图标
                    success: function() {
                        // 用户确认分享后执行的回调函数
                        var param = {
                            productType: $scope.item.productType,
                            productId: $scope.item.productCode
                        };
                        $faAPI.shops.productAddToShopsShare(param).then(function(json) {});
                    },
                    cancel: function() {
                        // 用户取消分享后执行的回调函数
                    }
                });
                $faWechat.api.onMenuShareAppMessage({
                    title: $scope.item.productShortName + '－金策师', // 分享标题
                    desc: '投资领域：'+$scope.item.investDesc+'；付息方式：'+$scope.item.paymentInterestTypeDesc+'；大小配比：'+$scope.item.pSizeRatioExplain, // 分享描述
                    link: $location.protocol() + '://' + $location.host() + '/#/product/xtzgdetail/' + $scope.item.productCode+'?share=true&sharePhone='+$scope.sharePhone, // 分享链接
                    imgUrl: $location.protocol() + '://' + $location.host()+$scope.item.pImageUrl, // 分享图标
                    type: 'link', // 分享类型,music、video或link，不填默认为link
                    dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
                    success: function() {
                        // 用户确认分享后执行的回调函数
                        var param = {
                            productType: $scope.item.productType,
                            productId: $scope.item.productCode
                        };
                        $faAPI.shops.productAddToShopsShare(param).then(function(json) {});
                    },
                    cancel: function() {
                        // 用户取消分享后执行的回调函数
                    }
                })
            }
            else{
                $faWechat.api.onMenuShareTimeline({
                    title: $scope.item.productShortName + '－金策师', // 分享标题
                    link: $location.protocol() + '://' + $location.host() + '/#/product/pevc/' + $scope.item.productCode,
                    imgUrl: $location.protocol() + '://' + $location.host()+$scope.item.pImageUrl, // 分享图标
                    success: function() {
                        // 用户确认分享后执行的回调函数
                        var param = {
                            productType: $scope.item.productType,
                            productId: $scope.item.productCode
                        };
                        $faAPI.shops.productAddToShopsShare(param).then(function(json) {});
                    },
                    cancel: function() {
                        // 用户取消分享后执行的回调函数
                    }
                });
                $faWechat.api.onMenuShareAppMessage({
                    title: $scope.item.productShortName + '－金策师', // 分享标题
                    desc: '发行机构：'+$scope.item.investOwner+'；组织形式：'+$scope.item.peOrganizeShape+'；基金类型：'+$scope.item.peFundShape, // 分享描述
                    link: $location.protocol() + '://' + $location.host() + '/#/product/pevc/' + $scope.item.productCode, // 分享链接
                    imgUrl: $location.protocol() + '://' + $location.host()+$scope.item.pImageUrl, // 分享图标
                    type: 'link', // 分享类型,music、video或link，不填默认为link
                    dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
                    success: function() {
                        // 用户确认分享后执行的回调函数
                        var param = {
                            productType: $scope.item.productType,
                            productId: $scope.item.productCode
                        };
                        $faAPI.shops.productAddToShopsShare(param).then(function(json) {});
                    },
                    cancel: function() {
                        // 用户取消分享后执行的回调函数
                    }
                })
            }
        }


        //分享后微信中添加后台统计
        function shopStatis(){
            //信托：110201
            //资管：110202
            //pevc：110203
            //阳光私募：110204
            var reqData = {
                type:'110203',
                host:$location.host(),
                path: $location.path(),
                param: $stateParams.id,
                source: 'WAP',
                shopId:$scope.sharePhone

            };
            $faAPI.shops.statis({
                type:'statisitics',
                data:reqData
            }).then(function(json){
            });
        }

        //扫码后微信中添加后台统计
        function shopSmStatis(){
            var reqData = {
                type: '110505',
                host: $location.host(),
                path: $location.path(),
                param: $location.search(),
                source: 'WAP',
                shopId: $scope.sharePhone,
                userId: $scope.sharePhone
            };
            $faAPI.shops.statis({
                type: 'statisitics',
                data: reqData
            }).then(function (json) {
            });
        }

        function getUserForLonginName(){
            if($stateParams.sharePhone){
                //根据分享的手机号码查询信息
                $faAPI.user.getUserForLonginName({
                    loginName:$stateParams.sharePhone,
                    productId:$scope.item.productCode,
                    productType:$scope.item.productType
                }).then(function(json){
                    $scope.sharePhoneInfo = json.dto;
                    $scope.tuijianReson = json.shopperProductDto.tuijianReson;

                    if(!issm) {
                        if ($faPlatform.weChat) {
                            //是否微信授权
                            if (!json.wechatId) {
                                $authorize.maAuth(shopStatis);
                            } else {
                                shopStatis()
                            }
                        }
                    } else {
                        shopSmStatis();
                    }

                    $scope.shopperUserInfoDto = json.shopperUserInfoDto;
                    $scope.productState = json.shopperProductDto.productState;
                });
            }
        }


        $scope.mailData = {};

        $faModal('send_mail','views/modals/sendMail.html',$scope,{
            initialize:function(){
                //console.log($scope.modal.send_mail());
            },
            done:function(){
                var self = this;

                $faAPI.product.sendMail({
                    pId:$scope.item.productId,
                    pType:$scope.item.productType,
                    emailAddress:$scope.mailData.sendMailUrl
                }).then(function(){
                    $ionicPopup.alert({
                        title:'发送邮件成功'
                    });
                    $rootScope.snedMailHistory.push($scope.mailData.sendMailUrl);
                    $rootScope.snedMailHistory = unique2($rootScope.snedMailHistory.reverse());
                    self.hide();
                });

            }
        });
        //发送邮件
        window.showSendMail = function(){
            $scope.modal.send_mail();
        };

        //清空发送邮件历史记录
        $scope.delsnedEmailHis = function(){
            $rootScope.snedMailHistory = [];
        };

        //复制简版功能提示
        //if($faPlatform.androidAPP || $faPlatform.IOSAPP){
        //    var hintv = document.getElementById('hintcopy');
        //    if(!window.localStorage.ishintCopy){
        //        hintv.style.display = 'block';
        //    }
        //    $scope.hidehintCopy = function(){
        //        hintv.style.display = 'none';
        //        window.localStorage.ishintCopy = true;
        //    };
        //}
        //复制简版
        $faModal('copy_brief','views/modals/copyBrief.html',$scope,{
            initialize:function(){
                $scope.copyType = 'pevc';
                //项目亮点
                try {
                    if($scope.pevcDetailData.result.flagBaoxiao){
                        $scope.copyisbaoxiao = '***SFA独家包销***';
                    }
                    $scope.copyxmld = $scope.summary.xmld?$scope.summary.xmld.replace(/<[^>]+>/g,""):'-';
                    if($faUser.info.isLogin){

                        $scope.copyuserinfo = '';
                        if($faUser.info.realName){
                            $scope.copyuserinfo = '联系人:'+$faUser.info.realName;
                        }
                        $scope.copyuserinfo =$scope.copyuserinfo +' 联系电话:'+$faUser.info.mobile;
                    }
                }catch(err){

                }

            },
            done:function(){
                var data = document.getElementById('copyData').value;

                if($faPlatform.androidAPP){
                    document.addEventListener("deviceready",OnDeviceReady, false);
                    function OnDeviceReady()
                    {
                        cordova.exec(null, null, "MyPlugin", "copy", [data]);
                    }
                }else{
                    copy(data);
                }

            }
        });
        window.showCopyBrief = function(){
            $scope.modal.copy_brief();
        };


        if(!$stateParams.sharePhone) {
            //产品详情埋点
            function shopProStatis() {
                //信托：110201
                //资管：110202
                //pevc：110203
                //阳光私募：110204
                var reqData = {
                    type: '110508',
                    host: $location.host(),
                    path: $location.path(),
                    param: $stateParams.id,
                    source: 'WAP',
                    shopId: $faUser.info.mobile

                };
                $faAPI.shops.statis({
                    type: 'statisitics',
                    data: reqData
                }).then(function (json) {
                });
            }
            shopProStatis();
        }

    })
    .controller('ProductSimuCtrl', function($scope,$stateParams,checkStatus,product, $faPopup, $faModal, $state, $rootScope, $faUser, $faMAP, $faAPI, $faWechat,$faUtil,$interval,$faPlatform,$ionicPopup,$location,$yukuvideo,$authorize) {
        //$rootScope.isUserLogin = checkStatus.loginStatus;
        var issm = $stateParams.issm;//是否通过扫码进入 true:是
        $scope.proid = $stateParams.id;

        $scope.share = $stateParams.share;
        $scope.sharePhone = $stateParams.sharePhone;
        $scope.onlypro=$stateParams.onlypro;
        $scope.item = product;

        console.log(product)

        $scope.isShowTool = true;
        $scope.islsyj = true;
        $scope.islsjz = true;
        $scope.islogin = false;
        $scope.item.detail.lsyjbJson = $scope.item.detail.lsyjbJson ? $faUtil.fromJson(($scope.item.detail.lsyjbJson).replace(/“/g, '"')) : false;
        $scope.item.detail.lsjzJson = $scope.item.detail.lsjzJson ? $faUtil.fromJson(($scope.item.detail.lsjzJson).replace(/“/g, '"')) : false;

        if($scope.item.detail.lsyjbJson == []){
            $scope.islsyj = false;
        }
        if($scope.item.detail.lsjzJson == []){
            $scope.islsjz = false;
        }
        $scope.chartType = 1;

        $scope.chartTypeChange = function(i) {
            $scope.chartType = i;
        };
        //优酷视频
        var sfavideo = product.detail.sfaVideo;

        if(sfavideo != undefined){
            if(sfavideo.isEncryption == 0){
                VIDEO_PWD = sfavideo.encryptionPassword;
            }else {
                VIDEO_PWD = '';
            }
            $yukuvideo.play(sfavideo.videoId,sfavideo.id);
        }
        function examinelogin(){
            $scope.user.info.isLogin = true;
        }
        $scope.gologin = function(){
            $rootScope.modal.login(examinelogin);
        };
        // 产品详情
        $faModal('simudetail_modal', 'views/modals/simudetail_modal.html', $scope, {});

        $scope.test = function(){
            if (!$faUser.info.isLogin) {
                $rootScope.modal.login();
            }
        };
        //私募预约
        $scope.goOrder = function(id){
            if($scope.simudetail_modal){
                $scope.simudetail_modal.hide();
            }
            $faUser.info.isLogin ? $state.go('product.xtzgOrder',{pid:id,type:true}) : $rootScope.modal.login();
        };
        //私募（店铺预约）
        //(店铺立刻预约)
        $scope.goClientOrder = function(id,type,name,phone){
            //点击预约需要关闭详情弹层
            if($scope.simudetail_modal){
                $scope.simudetail_modal.hide();
            };
            $state.go('product.clientOrder',{productId:id,productType:type,productName:name,sphone:phone});
        };
        $scope.openOrder = function() {
            $scope.modal.simudetail_modal();

        };


        //私募分享
        $scope.proshare = function(){
            //分享结束执行
            window.shareCallBack = function() {
                var param = {
                    productType: '01',
                    productId: $scope.item.detail.id
                };
                $faAPI.shops.productAddToShopsShare(param).then(function(json) {});
            };
            var data;
            if ($faUser.info.isLogin) {
                //阳光私募：基金类型、组织形式、结构形式
                data = {
                    title:$scope.item.detail.jjqc,
                    desc:'基金类型：'+$scope.item.detail.jjfl+'；组织形式：'+$scope.item.detail.zzxs+'；结构形式：'+$scope.item.detail.jgxs,
                    link:reqUrl + '/#/product/simu/' + $scope.item.detail.id+'?share=true&sharePhone='+$faUser.info.mobile,
                    imgUrl:'http://lec.superfa.cn/upload/bann/20160913/1473730864215990394.png'
                };
            }else {
                //阳光私募：基金类型、组织形式、结构形式
                data = {
                    title:$scope.item.detail.jjqc,
                    desc:'基金类型：'+$scope.item.detail.jjfl+'；组织形式：'+$scope.item.detail.zzxs+'；结构形式：'+$scope.item.detail.jgxs,
                    link:reqUrl + '/#/product/simu/' + $scope.item.detail.id+'?share=true',
                    imgUrl:'http://lec.superfa.cn/upload/bann/20160913/1473730864215990394.png'
                };
            }



            if($faPlatform.androidAPP){
                document.addEventListener("deviceready",OnDeviceReady, false);
                function OnDeviceReady()
                {
                    cordova.exec(null, null, "MyPlugin", "toShare", [data.title,data.desc,data.link,data.imgUrl]);
                }
                window.shareCallBack();
            }else{
                productShare(data.title,data.desc,data.link,data.imgUrl);
            }
        };
        //微信分享
        if($faUser.info.isLogin){
            $faWechat.api.onMenuShareTimeline({
                title: $scope.item.detail.jjmc + '－金策师', // 分享标题
                link: $location.protocol() + '://' + $location.host() + '/#/product/simu/' + $scope.item.detail.id+'?share=true&sharePhone='+$faUser.info.mobile, // 分享链接
                imgUrl: 'http://lec.superfa.cn/upload/bann/20160913/1473730864215990394.png', // 分享图标
                success: function() {
                    // 用户确认分享后执行的回调函数
                    var param = {
                        productType: '01',
                        productId: $scope.item.detail.id
                    };
                    $faAPI.shops.productAddToShopsShare(param).then(function(json) {});
                },
                cancel: function() {
                    // 用户取消分享后执行的回调函数
                }
            });
            $faWechat.api.onMenuShareAppMessage({
                title: $scope.item.detail.jjmc + '－金策师', // 分享标题
                desc: '基金类型：'+$scope.item.detail.jjfl+'；组织形式：'+$scope.item.detail.zzxs+'；结构形式：'+$scope.item.detail.jgxs, // 分享描述
                link: $location.protocol() + '://' + $location.host() + '/#/product/simu/' + $scope.item.detail.id+'?share=true&sharePhone='+$faUser.info.mobile, // 分享链接
                imgUrl: 'http://lec.superfa.cn/upload/bann/20160913/1473730864215990394.png', // 分享图标
                type: 'link', // 分享类型,music、video或link，不填默认为link
                dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
                success: function() {
                    // 用户确认分享后执行的回调函数
                    var param = {
                        productType: '01',
                        productId: $scope.item.detail.id
                    };
                    $faAPI.shops.productAddToShopsShare(param).then(function(json) {});
                },
                cancel: function() {
                    // 用户取消分享后执行的回调函数
                }
            })
        }
        else if($scope.share){
            //2016/12/08新增需求,APP分享出来后，没有登录，带分享人的信息
            $faWechat.api.onMenuShareTimeline({
                title: $scope.item.productShortName + '－金策师', // 分享标题
                link: $location.protocol() + '://' + $location.host() + '/#/product/xtzgdetail/' + $scope.item.productCode+'?share=true&sharePhone='+$scope.sharePhone,
                imgUrl: $location.protocol() + '://' + $location.host()+$scope.item.pImageUrl, // 分享图标
                success: function() {
                    // 用户确认分享后执行的回调函数
                    var param = {
                        productType: '01',
                        productId: $scope.item.detail.id
                    };
                    $faAPI.shops.productAddToShopsShare(param).then(function(json) {});
                },
                cancel: function() {
                    // 用户取消分享后执行的回调函数
                }
            });
            $faWechat.api.onMenuShareAppMessage({
                title: $scope.item.productShortName + '－金策师', // 分享标题
                desc: '投资领域：'+$scope.item.investDesc+'；付息方式：'+$scope.item.paymentInterestTypeDesc+'；大小配比：'+$scope.item.pSizeRatioExplain, // 分享描述
                link: $location.protocol() + '://' + $location.host() + '/#/product/xtzgdetail/' + $scope.item.productCode+'?share=true&sharePhone='+$scope.sharePhone, // 分享链接
                imgUrl: $location.protocol() + '://' + $location.host()+$scope.item.pImageUrl, // 分享图标
                type: 'link', // 分享类型,music、video或link，不填默认为link
                dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
                success: function() {
                    // 用户确认分享后执行的回调函数
                    var param = {
                        productType: '01',
                        productId: $scope.item.detail.id
                    };
                    $faAPI.shops.productAddToShopsShare(param).then(function(json) {});
                },
                cancel: function() {
                    // 用户取消分享后执行的回调函数
                }
            })
        }
        else{
            $faWechat.api.onMenuShareTimeline({
                title: $scope.item.detail.jjmc + '－金策师', // 分享标题
                link: $location.protocol() + '://' + $location.host() + '/#/product/simu/' + $scope.item.detail.id,
                imgUrl: 'http://lec.superfa.cn/upload/bann/20160913/1473730864215990394.png', // 分享图标
                success: function() {
                    // 用户确认分享后执行的回调函数
                    var param = {
                        productType: '01',
                        productId: $scope.item.detail.id
                    };
                    $faAPI.shops.productAddToShopsShare(param).then(function(json) {});
                },
                cancel: function() {
                    // 用户取消分享后执行的回调函数
                }
            });
            $faWechat.api.onMenuShareAppMessage({
                title: $scope.item.detail.jjmc + '－金策师', // 分享标题
                desc: '基金类型：'+$scope.item.detail.jjfl+'；组织形式：'+$scope.item.detail.zzxs+'；结构形式：'+$scope.item.detail.jgxs, // 分享描述
                link: $location.protocol() + '://' + $location.host() + '/#/product/simu/' + $scope.item.detail.id, // 分享链接
                imgUrl: 'http://lec.superfa.cn/upload/bann/20160913/1473730864215990394.png', // 分享图标
                type: 'link', // 分享类型,music、video或link，不填默认为link
                dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
                success: function() {
                    // 用户确认分享后执行的回调函数
                    var param = {
                        productType: '01',
                        productId: $scope.item.detail.id
                    };
                    $faAPI.shops.productAddToShopsShare(param).then(function(json) {});
                },
                cancel: function() {
                    // 用户取消分享后执行的回调函数
                }
            })
        }

        //分享后微信中添加后台统计
        function shopStatis(){
            //信托：110201
            //资管：110202
            //pevc：110203
            //阳光私募：110204
            var reqData = {
                type:'110204',
                host:$location.host(),
                path: $location.path(),
                param: $stateParams.id,
                source: 'WAP',
                shopId:$scope.sharePhone

            };
            $faAPI.shops.statis({
                type:'statisitics',
                data:reqData
            }).then(function(json){
            });
        }

        //扫码后微信中添加后台统计
        function shopSmStatis(){
            var reqData = {
                type: '110505',
                host: $location.host(),
                path: $location.path(),
                param: $location.search(),
                source: 'WAP',
                shopId: $scope.sharePhone,
                userId: $scope.sharePhone
            };
            $faAPI.shops.statis({
                type: 'statisitics',
                data: reqData
            }).then(function (json) {
            });
        }

        if($stateParams.sharePhone){
            //根据分享的手机号码查询信息

            $faAPI.user.getUserForLonginName({
                loginName:$stateParams.sharePhone,
                productId:$scope.item.detail.id,
                productType:'01'
            }).then(function(json){
                $scope.sharePhoneInfo = json.dto;
                $scope.tuijianReson = json.shopperProductDto.tuijianReson;

                if(!issm) {
                    if ($faPlatform.weChat) {
                        //是否微信授权
                        if (!json.wechatId) {
                            $authorize.maAuth(shopStatis);
                        } else {
                            shopStatis()
                        }
                    }
                } else {
                    shopSmStatis();
                }

                $scope.shopperUserInfoDto = json.shopperUserInfoDto;
                $scope.productState = json.shopperProductDto.productState;
            });
        } else {
            //产品详情埋点
            function shopProStatis() {
                //信托：110201
                //资管：110202
                //pevc：110203
                //阳光私募：110204
                var reqData = {
                    type: '110507',
                    host: $location.host(),
                    path: $location.path(),
                    param: $stateParams.id,
                    source: 'WAP',
                    shopId: $faUser.info.mobile

                };
                $faAPI.shops.statis({
                    type: 'statisitics',
                    data: reqData
                }).then(function (json) {
                });
            }
            shopProStatis();
        }

        $scope.mailData = {};
        $faModal('send_mail','views/modals/sendMail.html',$scope,{
            initialize:function(){
                //console.log($scope.modal.send_mail());
            },
            done:function(){
                var self = this;

                $faAPI.product.sendMail({
                    pId:$scope.item.detail.id,
                    pType:'01',
                    emailAddress:$scope.mailData.sendMailUrl
                }).then(function(){
                    $ionicPopup.alert({
                        title:'发送邮件成功'
                    });
                    $rootScope.snedMailHistory.push($scope.mailData.sendMailUrl);
                    $rootScope.snedMailHistory = unique2($rootScope.snedMailHistory.reverse());
                    self.hide();
                });

            }
        });

        //发送邮件
        window.showSendMail = function(){
            $scope.modal.send_mail();
        };

        //清空发送邮件历史记录
        $scope.delsnedEmailHis = function(){
            $rootScope.snedMailHistory = [];
        };
        //复制简版功能提示
        //if($faPlatform.androidAPP || $faPlatform.IOSAPP){
        //    var hintv = document.getElementById('hintcopy');
        //    if(!window.localStorage.ishintCopy){
        //        hintv.style.display = 'block';
        //    }
        //    $scope.hidehintCopy = function(){
        //        hintv.style.display = 'none';
        //        window.localStorage.ishintCopy = true;
        //    };
        //}
        //复制简版
        $faModal('copy_brief','views/modals/copyBrief.html',$scope,{
            initialize:function(){
                $scope.copyType = 'simu';

                try {
                    //认购须知
                    $scope.copybuynoticedetail = $scope.item.buynotice.buynoticedetail?$scope.item.buynotice.buynoticedetail.replace(/<[^>]+>/g,""):'-';
                    //项目亮点
                    $scope.copyproductadvantage = $scope.item.buynotice.productadvantage?$scope.item.buynotice.productadvantage.replace(/<[^>]+>/g,""):'-';
                    if($faUser.info.isLogin){

                        $scope.copyuserinfo = '';
                        if($faUser.info.realName){
                            $scope.copyuserinfo = '联系人:'+$faUser.info.realName;
                        }
                        $scope.copyuserinfo =$scope.copyuserinfo +' 联系电话:'+$faUser.info.mobile;
                    }
                }catch(err){

                }

            },
            done:function(){
                var data = document.getElementById('copyData').value;
                if($faPlatform.androidAPP){
                    document.addEventListener("deviceready",OnDeviceReady, false);
                    function OnDeviceReady()
                    {
                        cordova.exec(null, null, "MyPlugin", "copy", [data]);
                    }
                }else{
                    copy(data);
                }

            }
        });
        window.showCopyBrief = function(){
            $scope.modal.copy_brief();
        };


    })
    .controller('userUploadCtrl', function($scope, $rootScope, $stateParams, $faAPI, $faUser, $faPopup, $faModal, $q, $state,$ionicScrollDelegate, $ionicPopup, $faPlatform) {
        $faUser.update();

        //
        $scope.data = {
            paymentInterestType:'02',
            saleStatus:'02',
            productType:'集合信托'
        };
        var popTitle = '';
        var popButton = '';

        $scope.data.productName = $stateParams.pName;
        console.log($scope.data);
        if($stateParams.id){
            $faAPI.user.detailproupload({
                id:$stateParams.id
            }).then(function(json){
                console.log(json);
                $scope.data = json.dto;
                $scope.rebateRateList = angular.fromJson ($scope.data.revenue);
                $scope.moreDetail = $scope.data.fpShopUserRelProductDetailList;
            });
        }

1
        if($faUser.isCertEmpty()){
            popTitle = '您还未上传名片，上传并审核通过后才能上传产品';
            popButton = '去上传';
            pop();
        }else if($faUser.isCertIng()){
            popTitle = '您的名片还在审核中，审核通过后才能上传产品';
            popButton = '看名片';
            pop();
        }else if($faUser.isCertDeny()){
            popTitle = '您的名片审核失败，请重新上传';
            popButton = '去上传';
            pop();
        }

        function pop(){
            var myPopup = $ionicPopup.show({
                title: popTitle,
                scope: $scope,
                buttons: [
                    {
                        text: '取消',
                        type: 'confirmLoginCancel',
                        onTap: function(e) {
                            $state.go('app');
                        }
                    },
                    {
                        text: popButton,
                        type: 'button-positive confirmLogin',
                        onTap: function(e) {
                            $state.go('app.myself.certification', {repage:'app.upload'});
                        }
                    }
                ]
            });
        }

        //$scope.upload = {
        //    'productType': '02',
        //    'productName': '',
        //    'rebateType': '1',        // 1：按照投资金额返佣，2：按固定费率返佣
        //    'rebateRate': '',         // [{range:'100-200',rate:1.4},{range:'200-300',rate:1.6}]或'1.4'
        //    'flagAnonymous': '1',     // 是否匿名：匿名2、不匿名1
        //    'productInstruction': ''
        //};

        $scope.rebateRateList = [
            {minAmount:'', revenue:''}
        ];
        $scope.addRebateRate = function(){
            $scope.rebateRateList.push({minAmount:'', revenue:''});
        };
        $scope.removeRebateRate = function(i){
            if($scope.rebateRateList && $scope.rebateRateList.length > 1){
                $scope.rebateRateList.splice(i, 1);
            }
        };
        $scope.moreDetail = [];
        $scope.addTextInput = function(){
            $scope.moreDetail.push({relType:'1', relContent:''});
            console.log($scope.moreDetail);
            $ionicScrollDelegate.$getByHandle('prouploadScroll').scrollBottom();
        };
        $scope.addImgInput = function(){
            $scope.moreDetail.push({relType:'2', relImage:''});
            console.log($scope.moreDetail);
            $ionicScrollDelegate.$getByHandle('prouploadScroll').scrollBottom();
        };
        $scope.removeaddInput = function(i){

            $scope.moreDetail.splice(i, 1);
            console.log($scope.moreDetail);
        };
        //ios-选取图片
        var sleimgindex;
        $scope.cropPhotoShopHome = function(index){
            console.log(index);
            sleimgindex = index;
            

            if(!ISWEB){
                if($faPlatform.IOSAPP){
                    cropPhoto('sendImage6');
                }
                if($faPlatform.androidAPP){
                    document.addEventListener("deviceready", OnDeviceReady, false);
                    function OnDeviceReady() {
                        cordova.exec(null, null, "MyPlugin", "cropPhoto", ['sendImage6']);
                    }
                }
            }
        };
        //这个在IOS端回调的方法，在IOS webview里面是唯一的，如果方法重名，会调用其他重名的方法，此方法不生效。
        window.sendImage6 = function (url){
            $scope.moreDetail[sleimgindex] = {relType:'2', relImage:url};
            $scope.$apply();
        };


        //添加产品--提交
        $scope.saveUpload = function(){
            if(!$scope.data.productName){
                $faPopup.alert({
                    title: '请输入产品名称！'
                });
                return;
            }
            if(!$scope.data.issuingScale){
                $faPopup.alert({
                    title: '请输入募集规模！'
                });
                return;
            }
            if(!$scope.data.dueTime){
                $faPopup.alert({
                    title: '请输入产品期限！'
                });
                return;
            }

                var t = 0;
                var tt = 0;
                    var rebateRateList = angular.copy($scope.rebateRateList);
                    angular.forEach(rebateRateList, function(o){
                        if(o.minAmount &&  o.revenue){
                            if(isNaN(o.minAmount)){
                                tt++;
                            }
                        }else{
                            t++;
                        }

                         //angular.forEach(o, function(o2){
                         //  if(!o2)
                         //    t++;
                         //  else if(isNaN(o2))
                         //    tt++;
                         //});
                    });

                    if(t > 0){
                        $faPopup.alert({
                            title: '请输入产品收益！'
                        });
                        return;
                    }
                    if(tt > 0){
                        $faPopup.alert({
                            title: '请输入正确金额！'
                        });
                        return;
                    }



                // 保存
                console.log($scope.rebateRateList);
                $scope.data.revenue = angular.toJson($scope.rebateRateList);
                $scope.data.moreDetail = angular.toJson($scope.moreDetail);
                console.log($scope.data);
                if($stateParams.id){//编辑
                    delete $scope.data.publicStatus;//是否上下架
                    $faAPI.user.upproupload($scope.data).then(function(json){
                        if(!json.statusCode){
                            $state.go('app.uploadOk');
                        }
                    });
                }else {//新增
                    $faAPI.user.proupload($scope.data).then(function(json){
                        if(!json.statusCode){
                            $state.go('app.uploadOk');
                        }
                    });
                }


            };
            $scope.classifyList = [];
            $scope.classifyIssle = false;
            //产品管理--查询分类
            $scope.queryclassify = function(){
                $scope.classifyIssle = true;
                $faAPI.user.listFpShopProductType().then(function(json){
                    $scope.classifyList = json.list;
                    console.log($scope.classifyList);
                });
            };
            //产品管理--添加分类
            $scope.addclassify = function(){
                $scope.classifyname = {};
                var myPopup = $ionicPopup.show({
                    title: '添加分类',
                    template: '<input ng-model="classifyname.name" placeholder="请输入分类名称"/>',
                    inputPlaceholder: '10-50字',
                    scope: $scope,
                    buttons: [
                        {
                            text: '取消',
                            type: 'bolgsDeleteCancel'
                        },
                        {
                            text: '确认',
                            type: 'deletebolgs',
                            onTap: function(e) {
                                console.log($scope.classifyname.name);
                                $faAPI.user.addFpShopProductType({
                                    typeValue:$scope.classifyname.name
                                }).then(function(json){
                                    $faAPI.user.listFpShopProductType().then(function(json){
                                        $scope.classifyList = json.list;
                                        console.log($scope.classifyList);
                                    });
                                });
                            }
                        }
                    ]
                });


            };
            //产品管理--选择分类
            var sletemp;//临时储存选择词
            $scope.sleClassify = function(index,type){
                $scope.sleindex = index;
                sletemp = type;

                console.log(type);
                //$scope.classifyIssle = false;
            };
            //产品管理--添加分类--确定选择
            $scope.confirmSle = function(){
                $scope.data.productType = sletemp;
                $scope.classifyIssle = false;
            }


    })
    .controller('myProduct2DetailCtrl', function ($scope, $rootScope, $stateParams, $ionicScrollDelegate, $faModal, $location, $faAPI, $faPopup, $faUser, $faMAP, $state, product, $faLoading, $faIOSBridge, $ionicNavBarDelegate, $timeout, $faWechat, $faPlatform, $ionicPopup, $yukuvideo, $authorize, $filter, $faUtil) {


        //分享信息
        var issm=$stateParams.issm;
        $scope.proid=$stateParams.id;
        $scope.share = $stateParams.share;
        $scope.sharePhone = $stateParams.sharePhone;
        //用于单独产品分享后，去除返回按钮
        $scope.isshare = $stateParams.isshare;
        //是否协议价
        $scope.isagreement = false;
        //筛选图标状态
        $scope.isFilterSle = false;

        $scope.item = product.dto;
        console.log(product.dto);
        //产品详情由富文本拆分的字段
        try {

            $scope.revenue = JSON.parse(product.dto.revenue);
        }
        catch (err) {
        }



        function examinelogin() {
            $scope.user.info.isLogin = true;
        }

        $scope.gologin = function () {
            $rootScope.modal.login(examinelogin);
        };
        $faModal('xtzg_modal', 'views/modals/xtzgdetail_modal.html', $scope);
        $faModal('pevc_modal', 'views/modals/pevcdetail_modal.html', $scope);

        //产品详情
        $scope.openOrder = function (type) {
            if (type) {
                $scope.modal.xtzg_modal();
            } else {
                $scope.modal.pevc_modal();
            }
        };


        ////复制简版功能提示
        //if($faPlatform.androidAPP || $faPlatform.IOSAPP){
        //    var hintv = document.getElementById('hintcopy');
        //    if(!window.localStorage.ishintCopy){
        //        hintv.style.display = 'block';
        //    }
        //    $scope.hidehintCopy = function(){
        //        hintv.style.display = 'none';
        //        window.localStorage.ishintCopy = true;
        //    };
        //}





        $scope.params = $location.search();
        if ($scope.params.name) {
            $scope.uName = decodeURI($scope.params.name);
        }

        //if ($scope.params.share && window.location.href.indexOf('view') < 0 && window.location.href.indexOf('shop') < 0) {
        //    $timeout(function () {
        //        $ionicNavBarDelegate.showBar(false);
        //    }, 0);
        //}
        //竞价收单
        $scope.goBid = function (id) {
            if ($scope.xtzg_modal) {
                $scope.xtzg_modal.hide();
            }
            if ($scope.isagreement) {
                $ionicPopup.alert({
                    title: '协议价产品无法竞价',
                    okText: '好的',
                    okType: 'button-assertive'
                });
                return
            }
            if ($faUser.info.isLogin) {
                if (!$rootScope.userRole) {
                    $ionicPopup.confirm({
                        title: '你还未上传名片或在审核中,上传并审核通过后才能竞价收单',
                        cancelText: '取消',
                        okText: '去上传',
                        cancelType: '',
                        okType: 'button-assertive'
                    }).then(function (res) {

                        if (!res) {

                        }
                        if (res) {
                            $state.go('app.myself.certification')
                        }
                    });
                } else {
                    $faAPI.product.queryOldBiddingReceipt({
                        pId: id
                    }).then(function (res) {
                        if (res.flagOldBidding) {
                            $ionicPopup.confirm({
                                title: '你已提交过竞价,是否继续？',
                                cancelText: '取消',
                                okText: '继续竞价',
                                cancelType: '',
                                okType: 'button-assertive'
                            }).then(function (res) {
                                if (res) {
                                    $state.go('product.bidding', {pid: id})
                                }
                            });
                        } else {
                            $state.go('product.bidding', {pid: id})
                        }
                    });
                }


            } else {
                $rootScope.modal.login();
            }


        };
        //立即预约
        $scope.goOrder = function (id) {
            //点击预约需要关闭详情弹层
            if ($scope.xtzg_modal) {
                $scope.xtzg_modal.hide();
            }
            if ($scope.pevc_modal) {
                $scope.pevc_modal.hide();
        }
            $faUser.info.isLogin ? $state.go('product.xtzgOrder', {pid: id}) : $rootScope.modal.login();
        };

        //(店铺立刻预约)
        //self--是否自营产品
        $scope.goClientOrder = function (id, type, name, phone) {
            //点击预约需要关闭详情弹层
            if ($scope.xtzg_modal) {
                $scope.xtzg_modal.hide();
            }
            if ($scope.pevc_modal) {
                $scope.pevc_modal.hide();
            }
            $state.go('product.clientOrder', {productId: id, productType: type, productName: name, sphone: phone,self:true});
        };
        $scope.goCertification = function ($event) {
            $event.stopPropagation();
            $faUser.info.isLogin ? $state.go('app.myself.certification') : $rootScope.modal.login();
        };
        //放弃承销
        $scope.giveup = function (id) {
            if ($scope.xtzg_modal) {
                $scope.xtzg_modal.hide();
            }

            var giveupPopup = $ionicPopup.confirm({
                title: '是否放弃承销权?',
                buttons: [
                    {text: '取消'},
                    {
                        text: '<b>确定</b>',
                        type: 'button-default',
                        onTap: function (e) {
                            e.preventDefault();
                            $faAPI.product.dropBiddingReceipt({
                                biddingReceiptId: id
                            }).then(function (res) {
                                giveupPopup.close();
                                $scope.res.biddingReceiptUserInfo.currentBiddingIsLogin = false;
                            });
                        }
                    }]
            });
        };
        //是否活动主推
        $scope.isM2bProduct = function (product) {
            var flag = false, product = product || {};
            if (product && product.activitiesMollionsWealthList && product.activitiesMollionsWealthList.length) {
                angular.forEach(product.activitiesMollionsWealthList, function (o) {
                    if (o.activitiesProductType == "04") {
                        flag = true;
                    }
                });
            }
            return flag;
        };
        //分享后微信中添加后台统计
        function shopStatis() {
            //信托：110201
            //资管：110202
            //pevc：110203
            //阳光私募：110204
            var reqData = {
                type: '110209',
                host: $location.host(),
                path: $location.path(),
                param: $stateParams.id,
                source: 'WAP',
                shopId: $scope.sharePhone

            };
            $faAPI.shops.statis({
                type: 'statisitics',
                data: reqData
            }).then(function (json) {
                console.log('发送统计成功');
            });
        }

        //扫码后微信中添加后台统计
        function shopSmStatis(){
            var reqData = {
                type: '110505',
                host: $location.host(),
                path: $location.path(),
                param: $location.search(),
                source: 'WAP',
                shopId: $scope.sharePhone,
                userId: $scope.sharePhone
            };
            $faAPI.shops.statis({
                type: 'statisitics',
                data: reqData
            }).then(function (json) {
            });
        }

        //根据分享的手机号码查询信息
        if ($stateParams.sharePhone) {

            $faAPI.user.getUserForLonginName({
                loginName: $stateParams.sharePhone,
                productId: product.dto.id,
                productType: product.dto.productType

            }).then(function (json) {
                //2017/12/12  取店铺的信息--up
                $scope.shopuserdto = json.dto;
                $scope.sharePhoneInfo = json.shopperUserInfoDto;
                console.log($scope.sharePhoneInfo);
                $scope.tuijianReson = json.shopperProductDto.tuijianReson;

                if(!issm) {
                    if ($faPlatform.weChat) {
                        //是否微信授权
                        if (!json.wechatId) {
                            $authorize.maAuth(shopStatis);
                        } else {
                            shopStatis()
                        }
                    }
                } else {
                    shopSmStatis();
                }
                console.log(json)
                $scope.shopperUserInfoDto = json.shopperUserInfoDto;

            });
        }

        // 收藏

        // 判断是否收藏

        if ($faUser.info.isLogin) {
            $faAPI.product.starList({
                pId: $scope.item.productId

            }).then(function (json) {

                if (json.list.length > 0) {
                    $scope.item.starId = json.list[0].id
                }

            });
        }
        // 加入收藏
        $scope.star = function () {
            if ($faUser.info.isLogin) {
                if (!$scope.item.starId) {
                    $faAPI.product.star({
                        pId: $scope.item.productId,
                        likeType: '1'
                    }).then(function (json) {
                        $scope.item.starId = json.id;
                    });

                } else {
                    $faAPI.product.cancelStar({
                        id: $scope.item.starId,
                        pId: $scope.item.productId
                    }).then(function () {
                        delete $scope.item.starId;
                    });
                }
            } else {
                $rootScope.modal.login();
            }
        };

        // 留言列表
        $faModal('comment', 'views/product/comment.html', $scope, {
            initialize: function () {
                var self = this;

                self.pager = {
                    hasNaxtPage: true,
                    pageSize: 10,
                    nextPage: 1,
                };

                $scope.comments = [];
            },
            loadMoreItems: function () {

                var self = this;

                self.data = {
                    _pId: $scope.item.productId,
                    pageNo: self.pager.nextPage,
                    pageSize: self.pager.pageSize
                };

                $faAPI.productComment.list(self.data).then(function (json) {
                    $scope.comments = $scope.comments.concat(json.list);
                    self.pager = json.pager;
                    $scope.$broadcast('scroll.infiniteScrollComplete');
                });
            },
            up: function (index, id) {

                var data = {
                    pCommentsId: id
                };

                if ($faUser.info.isLogin) {

                    $faAPI.productComment.up(data).then(function () {
                        $scope.comments[index].upCount += 1;
                    });

                } else {
                    $rootScope.modal.login();
                }

            }
        });

        // 写留言
        $faModal('writeComment', 'views/product/writeComment.html', $scope, {
            initialize: function () {

                var self = this;

                self.data = {
                    pId: $scope.item.productId
                };


            },
            done: function () {

                var self = this;

                if (!self.data.pCommentsContent) {
                    $faPopup.alert({
                        title: '请输入评论内容'
                    })
                } else {

                    if ($faUser.info.isLogin) {

                        $faAPI.productComment.add(self.data).then(function (json) {

                            var data = {
                                _pId: $scope.item.productId,
                                _pt: 'wap'
                            }


                            $scope.comments.unshift(json.list[0]);

                            self.hide();

                        });

                    } else {
                        $rootScope.modal.login();
                    }


                }

            }
        });

        // 下载附件
        $faModal('download', 'views/product/download.html', $scope, {
            done: function (id) {

                var self = this;

                var data = {
                    id: id,
                    pId: $scope.item.productId
                };

                if ($faUser.info.isLogin) {

                    $faAPI.product.download(data).then(function () {
                        self.hide();
                    });

                } else {
                    $rootScope.modal.login();
                }

            }
        });

        // 产品预约
        $faModal('order', 'views/product/order.html', $scope, {
            initialize: function () {
                var self = this;
                self.data = {};
                self.data.pid = $scope.item.productId;
            },
            done: function () {
                var self = this;

                if (!self.data.name) {

                    $faPopup.alert({
                        title: '请输入您的姓名'
                    });

                } else if (!$faMAP.regular.name.test(self.data.name)) {

                    $faPopup.alert({
                        title: '姓名格式输入有误'
                    });

                } else if (!self.data.mobile) {

                    $faPopup.alert({
                        title: '请输入您的手机号码'
                    });

                } else if (!$faMAP.regular.mobile.test(self.data.mobile)) {

                    $faPopup.alert({
                        title: '手机格式输入有误'
                    });

                } else if (!self.data.amount) {

                    $faPopup.alert({
                        title: '请输入您的预约金额'
                    });

                } else if (!$faMAP.regular.integer.test(self.data.amount)) {

                    $faPopup.alert({
                        title: '预约金额输入格式有误'
                    });

                } else {

                    $faAPI.order.applyPre(self.data).then(function (json) {
                        $faPopup.alert({
                            title: '预约成功，请等待专业顾问回复'
                        });
                        $state.go('app.deal');
                        self.hide();
                    });

                }

            }
        });
        $scope.openWriteComm = function () {
            if (!$faUser.info.isLogin) {
                $rootScope.modal.login();
            } else {
                $scope.modal.writeComment();
            }
        };
        $scope.orderOpen = function () {
            if (!$faUser.info.isLogin) {
                $rootScope.modal.login();
            } else {
                $scope.modal.order();
            }
        };


        //分享产品详情
        $scope.proshare = function () {
            //分享结束执行
            window.shareCallBack = function () {
                var param = {
                    productType: $scope.item.productType,
                    productId: $scope.item.productCode
                };
                $faAPI.shops.productAddToShopsShare(param).then(function (json) {
                });
            }
            //微信简版版本
            //未登录的情况下也可以分享产品
            var data;
            if ($faUser.info.isLogin) {
                //$rootScope.modal.login();
                //5.信托、资管：投资领域、付息方式、大小配比
                data = {
                    title: $scope.item.productShortName,
                    desc: '投资领域：' + $scope.item.investDesc + '；付息方式：' + $scope.item.paymentInterestTypeDesc + '；大小配比：' + $scope.item.pSizeRatioExplain,
                    link: reqUrl + '/#/product/xtzgdetail/' + $scope.item.productCode + '?share=true&sharePhone=' + $faUser.info.mobile,
                    imgUrl: citeImgUrl + $scope.item.pImageUrl
                };

            } else {
                data = {
                    title: $scope.item.productShortName,
                    desc: '投资领域：' + $scope.item.investDesc + '；付息方式：' + $scope.item.paymentInterestTypeDesc + '；大小配比：' + $scope.item.pSizeRatioExplain,
                    link: reqUrl + '/#/product/xtzgdetail/' + $scope.item.productCode + '?share=true',
                    imgUrl: citeImgUrl + $scope.item.pImageUrl
                };
            }


            if ($faPlatform.androidAPP) {
                document.addEventListener("deviceready", OnDeviceReady, false);
                function OnDeviceReady() {
                    cordova.exec(null, null, "MyPlugin", "toShare", [data.title, data.desc, data.link, data.imgUrl]);
                }

                window.shareCallBack();
            } else {
                productShare(data.title, data.desc, data.link, data.imgUrl);
            }

        };
        //ng-model绑定input输入获取值要定义成对象
        //http://jimhoskins.com/2012/12/14/nested-scopes-in-angularjs.html
        $scope.mailData = {};

        $faModal('send_mail', 'views/modals/sendMail.html', $scope, {
            initialize: function () {
                //console.log($scope.modal.send_mail());
            },
            done: function () {
                var self = this;
                $faAPI.product.sendMail({
                    pId: $scope.item.productId,
                    pType: $scope.item.productType,
                    emailAddress: $scope.mailData.sendMailUrl
                }).then(function () {
                    $ionicPopup.alert({
                        title: '发送邮件成功'
                    });
                    $rootScope.snedMailHistory.push($scope.mailData.sendMailUrl);
                    $rootScope.snedMailHistory = unique2($rootScope.snedMailHistory.reverse());
                    $scope.mailData.sendMailUrl = null;
                    self.hide();
                });

            }
        });

        //发送邮件--使用全局函数让native调用
        window.showSendMail = function () {
            $scope.modal.send_mail();
        };

        //清空发送邮件历史记录
        $scope.delsnedEmailHis = function () {
            $rootScope.snedMailHistory = [];
        };


        //复制简版
        $faModal('copy_brief', 'views/modals/copyBrief.html', $scope, {
            initialize: function () {
                $scope.copyType = 'xtzg';
                //是否包销
                if (product.result.flagBaoxiao) {
                    $scope.copyisbaoxiao = '***SFA独家包销***';
                }
                //资金用途
                $scope.copyzjyt = $scope.summary.zjyt ? $scope.summary.zjyt.replace(/<[^>]+>/g, "") : '-';
                //风险控制
                $scope.copyfxkz = $scope.summary.fxkz ? $scope.summary.fxkz.replace(/<[^>]+>/g, "") : '-';
                //产品优势
                $scope.copycpys = $scope.summary.cpys ? $scope.summary.cpys.replace(/<[^>]+>/g, "") : '-';
                //募集账号
                $scope.copymjzh = $scope.summary.mjzh ? $scope.summary.mjzh.replace(/<[^>]+>/g, "") : '-';
                if ($faUser.info.isLogin) {

                    $scope.copyuserinfo = '';
                    if ($faUser.info.realName) {
                        $scope.copyuserinfo = '联系人:' + $faUser.info.realName;
                    }
                    $scope.copyuserinfo = $scope.copyuserinfo + ' 联系电话:' + $faUser.info.mobile;
                }

            },
            done: function () {
                var data = document.getElementById('copyData').value;

                if ($faPlatform.androidAPP) {
                    document.addEventListener("deviceready", OnDeviceReady, false);
                    function OnDeviceReady() {
                        cordova.exec(null, null, "MyPlugin", "copy", [data]);
                    }
                } else {
                    copy(data);
                }

            }
        });
        window.showCopyBrief = function () {
            $scope.modal.copy_brief();
        };
        function h5Copy(data, name) {
            var clipboard = new Clipboard('.' + name, {
                text: function () {
                    return data;
                }
            });
            var myPopup = $ionicPopup.show({
                title: '复制成功',
                scope: $scope,
                buttons: []
            });
            $timeout(function () {
                myPopup.close(); //由于某种原因3秒后关闭弹出
            }, 2000);
        }

        function androidCopy(data) {

            document.addEventListener("deviceready", OnDeviceReady, false);
            function OnDeviceReady() {
                cordova.exec(null, null, "MyPlugin", "copy", [data]);
            }

        }

        //复制模块
        $scope.copyInfo = function (name) {

            if (name == 'jcxx') {
                var data = '【产品全称】：' + $scope.item.productName + '\n' +
                    '【募集规模】：' + $filter('abbrMoney')($scope.item.allIssuingScale) + '\n' +
                    '【投资领域】：' + $scope.item.investDesc + '\n' +
                    '【付息方式】：' + $scope.item.paymentInterestTypeDesc + '\n' +
                    '【大小配比】：' + $scope.item.pSizeRatioExplain + '\n' +
                    '【发行机构】：' + $scope.item.investOwner + '\n' +
                    '【投资期限】：' + $scope.item.dueTime + '个月' + '\n' +
                    '【发行时间】：' + $scope.item.saleDateStart.split(' ')[0];
                if (ISWEB) {
                    h5Copy(data, 'jcxx');
                } else {
                    if ($faPlatform.androidAPP) {
                        androidCopy(data);
                    } else {
                        copy(data);
                    }

                }


            }
            if (name == 'cpys') {
                var data = $scope.summary.cpys.replace(/<[a-z]+>/g, '')
                    .replace(/<[^>]+>/g, '\n').replace(/\n+/g, '\n');
                if (ISWEB) {
                    h5Copy(data, 'cpys');
                } else {
                    if ($faPlatform.androidAPP) {
                        androidCopy(data);
                    } else {
                        copy(data);
                    }

                }

            }
            if (name == 'mjzh') {
                var data = $scope.summary.mjzh.replace(/<[a-z]+>/g, '')
                    .replace(/<[^>]+>/g, '\n').replace(/\n+/g, '\n');
                if (ISWEB) {
                    h5Copy(data, 'mjzh');
                } else {
                    if ($faPlatform.androidAPP) {
                        androidCopy(data);
                    } else {
                        copy(data);
                    }

                }

            }
            if (name == 'fxkz') {

                var data = $scope.summary.fxkz.replace(/<[a-z]+>/g, '')
                    .replace(/<[^>]+>/g, '\n').replace(/\n+/g, '\n');

                if (ISWEB) {
                    h5Copy(data, 'fxkz');
                } else {
                    if ($faPlatform.androidAPP) {
                        androidCopy(data);
                    } else {
                        copy(data);
                    }
                }

            }


        };


        //微信分享---注释-2017/10/12
        //if ($faUser.info.isLogin) {
        //    $faWechat.api.onMenuShareTimeline({
        //        title: $scope.item.productShortName + '－理财师工具', // 分享标题
        //        link: $location.protocol() + '://' + $location.host() + '/#/product/xtzgdetail/' + $scope.item.productCode + '?share=true&sharePhone=' + $faUser.info.mobile, // 分享链接
        //        imgUrl: $location.protocol() + '://' + $location.host() + $scope.item.pImageUrl, // 分享图标
        //        success: function () {
        //            // 用户确认分享后执行的回调函数
        //            var param = {
        //                productType: $scope.item.productType,
        //                productId: $scope.item.productCode
        //            };
        //            $faAPI.shops.productAddToShopsShare(param).then(function (json) {
        //            });
        //        },
        //        cancel: function () {
        //            // 用户取消分享后执行的回调函数
        //        }
        //    });
        //    $faWechat.api.onMenuShareAppMessage({
        //        title: $scope.item.productShortName + '－理财师工具', // 分享标题
        //        desc: '投资领域：' + $scope.item.investDesc + '；付息方式：' + $scope.item.paymentInterestTypeDesc + '；大小配比：' + $scope.item.pSizeRatioExplain, // 分享描述
        //        link: $location.protocol() + '://' + $location.host() + '/#/product/xtzgdetail/' + $scope.item.productCode + '?share=true&sharePhone=' + $faUser.info.mobile, // 分享链接
        //        imgUrl: $location.protocol() + '://' + $location.host() + $scope.item.pImageUrl, // 分享图标
        //        type: 'link', // 分享类型,music、video或link，不填默认为link
        //        dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
        //        success: function () {
        //            // 用户确认分享后执行的回调函数
        //            var param = {
        //                productType: $scope.item.productType,
        //                productId: $scope.item.productCode
        //            };
        //            $faAPI.shops.productAddToShopsShare(param).then(function (json) {
        //            });
        //        },
        //        cancel: function () {
        //            // 用户取消分享后执行的回调函数
        //        }
        //    })
        //}
        //else if ($scope.share) {
        //    //2016/12/08新增需求,APP分享出来后，没有登录，带分享人的信息
        //    $faWechat.api.onMenuShareTimeline({
        //        title: $scope.item.productShortName + '－理财师工具', // 分享标题
        //        link: $location.protocol() + '://' + $location.host() + '/#/product/xtzgdetail/' + $scope.item.productCode + '?share=true&sharePhone=' + $scope.sharePhone,
        //        imgUrl: $location.protocol() + '://' + $location.host() + $scope.item.pImageUrl, // 分享图标
        //        success: function () {
        //            // 用户确认分享后执行的回调函数
        //            var param = {
        //                productType: $scope.item.productType,
        //                productId: $scope.item.productCode
        //            };
        //            $faAPI.shops.productAddToShopsShare(param).then(function (json) {
        //            });
        //        },
        //        cancel: function () {
        //            // 用户取消分享后执行的回调函数
        //        }
        //    });
        //    $faWechat.api.onMenuShareAppMessage({
        //        title: $scope.item.productShortName + '－理财师工具', // 分享标题
        //        desc: '投资领域：' + $scope.item.investDesc + '；付息方式：' + $scope.item.paymentInterestTypeDesc + '；大小配比：' + $scope.item.pSizeRatioExplain, // 分享描述
        //        link: $location.protocol() + '://' + $location.host() + '/#/product/xtzgdetail/' + $scope.item.productCode + '?share=true&sharePhone=' + $scope.sharePhone, // 分享链接
        //        imgUrl: $location.protocol() + '://' + $location.host() + $scope.item.pImageUrl, // 分享图标
        //        type: 'link', // 分享类型,music、video或link，不填默认为link
        //        dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
        //        success: function () {
        //            // 用户确认分享后执行的回调函数
        //            var param = {
        //                productType: $scope.item.productType,
        //                productId: $scope.item.productCode
        //            };
        //            $faAPI.shops.productAddToShopsShare(param).then(function (json) {
        //            });
        //        },
        //        cancel: function () {
        //            // 用户取消分享后执行的回调函数
        //        }
        //    })
        //} else {
        //
        //    $faWechat.api.onMenuShareTimeline({
        //        title: $scope.item.productShortName + '－理财师工具', // 分享标题
        //        link: $location.protocol() + '://' + $location.host() + '/#/product/xtzgdetail/' + $scope.item.productCode,
        //        imgUrl: $location.protocol() + '://' + $location.host() + $scope.item.pImageUrl, // 分享图标
        //        success: function () {
        //            // 用户确认分享后执行的回调函数
        //            var param = {
        //                productType: $scope.item.productType,
        //                productId: $scope.item.productCode
        //            };
        //            $faAPI.shops.productAddToShopsShare(param).then(function (json) {
        //            });
        //        },
        //        cancel: function () {
        //            // 用户取消分享后执行的回调函数
        //        }
        //    });
        //    $faWechat.api.onMenuShareAppMessage({
        //        title: $scope.item.productShortName + '－理财师工具', // 分享标题
        //        desc: '投资领域：' + $scope.item.investDesc + '；付息方式：' + $scope.item.paymentInterestTypeDesc + '；大小配比：' + $scope.item.pSizeRatioExplain, // 分享描述
        //        link: $location.protocol() + '://' + $location.host() + '/#/product/xtzgdetail/' + $scope.item.productCode, // 分享链接
        //        imgUrl: $location.protocol() + '://' + $location.host() + $scope.item.pImageUrl, // 分享图标
        //        type: 'link', // 分享类型,music、video或link，不填默认为link
        //        dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
        //        success: function () {
        //            // 用户确认分享后执行的回调函数
        //            var param = {
        //                productType: $scope.item.productType,
        //                productId: $scope.item.productCode
        //            };
        //            $faAPI.shops.productAddToShopsShare(param).then(function (json) {
        //            });
        //        },
        //        cancel: function () {
        //            // 用户取消分享后执行的回调函数
        //        }
        //    })
        //}

        //产品推荐

        //$faAPI.product.getRecommendProductForProductInfo({
        //    pId: product.result.productId
        //}).then(function (json) {
        //    console.log(json);
        //    $scope.recommendProduct = json.list || [];
        //});


        //加入对比
        $scope.addContrast = function ($event, code, name) {

            $event.stopPropagation();

            $rootScope.contrastData[name] = code;

            //console.log($rootScope.contrastData);

            $faUtil.localStorage('contrastData', $rootScope.contrastData);
            $state.go('contrastIndex');

        }


    })
    .controller('proAddMoreCtrl', function ($scope, $rootScope, $stateParams, $ionicScrollDelegate, $faModal, $location, $faAPI, $faPopup, $faUser, $faMAP, $state,$faLoading, $faIOSBridge, $ionicNavBarDelegate, $timeout, $faWechat, $faPlatform, $ionicPopup, $filter, $faUtil) {
        $scope.reqData = [];
        $scope.addTextInput = function(){
            $scope.reqData.push({relType:'1', relContent:''});
            console.log($scope.reqData);
        };
        $scope.addImgInput = function(){
            $scope.reqData.push({relType:'2', relImage:''});
            console.log($scope.reqData);
        };

        $scope.removeRebateRate = function(i){
            if($scope.rebateRateList && $scope.rebateRateList.length > 1){
                $scope.rebateRateList.splice(-1, 1);
            }
        };
        $scope.proAddMoreCommit = function(){
            console.log($scope.reqData);

            $faAPI.user.proupload().then(function(json){
                if(!json.statusCode){
                    $state.go('app.uploadOk');
                }
            });
        }
    })
;

